-
-
Save jesselima/119f644f10e3ce543fed0356442f3b56 to your computer and use it in GitHub Desktop.
HelperUtil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelperUtil { | |
public static HelperUtilBase getInstance(Context context) { | |
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { | |
return new HelperUtilL(context); | |
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | |
return new HelperUtilKK(context); | |
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
return new HelperUtilJB(context); | |
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { | |
return new HelperUtilICS(context); | |
} else { | |
return new HelperUtilBase(context); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelperUtilBase { | |
protected Context mContext; | |
public HelperUtilBase(Context context){ | |
this.mContext = context; | |
} | |
public void setActionBar() { | |
// Do nothing pre-L | |
} | |
public void setElevation(View view, float elevation){ | |
// Do nothing pre-L | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TargetApi(Build.VERSION_CODES.KITKAT) | |
public class HelperUtilKK extends HelperUtilBase{ | |
public HelperUtilKK(Context context) { | |
super(context); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TargetApi(Build.VERSION_CODES.L) | |
public class HelperUtilL extends HelperUtilBase{ | |
private Toolbar mActionBarToolbar; | |
public HelperUtilL(Context context) { | |
super(context); | |
} | |
@Override | |
public void setElevation(View view, float elevation){ | |
view.setElevation(elevation); | |
} | |
@Override | |
public void setActionBar() { | |
mActionBarToolbar = (Toolbar) ((Activity)mContext).findViewById(R.id.toolbar); | |
if (mActionBarToolbar != null) { | |
((Activity)mContext).setActionBar(mActionBarToolbar); | |
} | |
} | |
//...... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
HelperUtilBase helper; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
helper = HelperUtil.getInstance(this); | |
//.... | |
helper.setActionBar(); | |
helper.setElevation(cardView, 4.0f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment