-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/github/koooe/ganke/util/ColoredSnackbar.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.koooe.ganke.util; | ||
|
||
import android.support.design.widget.Snackbar; | ||
import android.view.View; | ||
|
||
/** | ||
* 设置snackbar颜色 | ||
*/ | ||
public class ColoredSnackbar { | ||
|
||
private static final int red = 0xfff44336; | ||
private static final int green = 0xff4caf50; | ||
private static final int blue = 0xff2195f3; | ||
private static final int orange = 0xffffc107; | ||
|
||
private static View getSnackBarLayout(Snackbar snackbar) { | ||
if (snackbar != null) { | ||
return snackbar.getView(); | ||
} | ||
return null; | ||
} | ||
|
||
private static Snackbar colorSnackBar(Snackbar snackbar, int colorId) { | ||
View snackBarView = getSnackBarLayout(snackbar); | ||
if (snackBarView != null) { | ||
snackBarView.setBackgroundColor(colorId); | ||
} | ||
|
||
return snackbar; | ||
} | ||
|
||
public static Snackbar info(Snackbar snackbar) { | ||
return colorSnackBar(snackbar, blue); | ||
} | ||
|
||
public static Snackbar warning(Snackbar snackbar) { | ||
return colorSnackBar(snackbar, orange); | ||
} | ||
|
||
public static Snackbar alert(Snackbar snackbar) { | ||
return colorSnackBar(snackbar, red); | ||
} | ||
|
||
public static Snackbar confirm(Snackbar snackbar) { | ||
return colorSnackBar(snackbar, green); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.koooe.ganke.util; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
/** | ||
* 很方便的once | ||
* Created by drakeet on 8/16/15. | ||
*/ | ||
public class Once { | ||
|
||
SharedPreferences mSharedPreferences; | ||
Context mContext; | ||
|
||
public Once(Context context) { | ||
mSharedPreferences = context.getSharedPreferences("once", Context.MODE_PRIVATE); | ||
mContext = context; | ||
} | ||
|
||
public void show(String tagKey, OnceCallback callback) { | ||
boolean isSecondTime = mSharedPreferences.getBoolean(tagKey, false); | ||
if (!isSecondTime) { | ||
callback.onOnce(); | ||
SharedPreferences.Editor editor = mSharedPreferences.edit(); | ||
editor.putBoolean(tagKey, true); | ||
editor.apply(); | ||
} | ||
} | ||
|
||
public void show(int tagKeyResId, OnceCallback callback) { | ||
show(mContext.getString(tagKeyResId), callback); | ||
} | ||
|
||
public interface OnceCallback { | ||
void onOnce(); | ||
} | ||
} |