I am making a collection of small utilities required by most of the android developers in daily life like
isFirstRun()
,isDataAvailable()
,getScreenHeight()
and many more.
Why write something again when it's already written ?
- Add dependency in your module's
build.gradle
file
dependencies {
// ... other dependencies here
compile 'com.md.phlex:phlex:0.0.2'
}
- Sync your project with gradle file.
- Start using methods. Like
Phlex.isFirstRun(this)
-
isFirstRun(SharedPreferences sharedPreferences)
- Returns
true
orfalse
- Returns
-
isFirstRun(Context context)
- Returns
true
orfalse
- Uses apps default SharedPreferences file
- Returns
-
isDataAvailable(Context context)
- Returns
true
orfalse
- Returns
-
isEmailIdValid(String emailId)
- Returns
true
orfalse
- Returns
-
isAppVersionUpdated(Context context)
- Returns
true
ifversionCode
of build.gradle is incremented - By default returns true on first run.
- Returns
-
isAppVersionUpdated(Context context, SharedPreferences sharedPreferences)
- Same as above method it just uses SharedPreferences file provided by user
-
getScreenWidth()
orgetScreenWidth()
- Returns integer value
-
getXPercentOfY(int X, int Y)
- You can also use float, long or double
- Returns value depending on datatype used
-
getThisFromAssets(Context context, String fileName)
- Returns contents of files as a
String
- Provide file name with extension like
sample.json
- Tip: Use with text files like *.txt, *.json etc
- Returns contents of files as a
-
switchfragment(AppCompatActivity activity, View container, Fragment fragment)
- Switches
fragment
in thecontainer
view
- Switches
-
switchfragment(AppCompatActivity activity, View container, Fragment fragment, String toolbarTitle)
- Switches
fragment
in thecontainer
view - Also changes the toolbar's title if available
- Switches
-
setToolbarElevation(Toolbar toolbar, View toolbarShadow, int elevation)
- Sets toolbar elevation to
elevation
if device is LOLLIPOP+ and hidestoolbarShadow
view - Else unhides
toolbarShadow
view - Tip: Very useful for backward compatibility
- Sets toolbar elevation to
-
isPreLollipop()
- Returns
true
if device is pre-lollipop - Tip: Useful for backward compatibility
- Returns
-
isLollipopPlusp()
- Returns
true
if device is lollipop or lollipop plus - Tip: Useful for backward compatibility
- Returns
-
dp2px(int dp)
- Returns
px
value of the provideddp
- You can also use
float
- Returns
-
px2dp(int px)
- Returns
dp
value of the providedpx
- You can also use
float
- Returns
-
isAppInstalled(Context context, String appPackageName)
- Returns
true
orfalse
- Returns
Note: I know this is too less but more methods will be available soon. You can send your ideas or contributions to me at [email protected]
Copyright 2016 MD Danish Ansari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.