Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to use HeaderColor in config.xml
- Loading branch information
Showing
3 changed files
with
43 additions
and
27 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
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
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 |
---|---|---|
@@ -1,31 +1,42 @@ | ||
package tomloprod; | ||
package tomloprod; | ||
|
||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.CordovaPlugin; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import android.app.ActivityManager; | ||
import android.os.Build; | ||
import android.graphics.Color; | ||
import android.content.Context; | ||
import org.apache.cordova.CallbackContext; | ||
import org.apache.cordova.CordovaInterface; | ||
import org.apache.cordova.CordovaPlugin; | ||
import org.apache.cordova.CordovaWebView; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import android.app.ActivityManager; | ||
import android.os.Build; | ||
import android.graphics.Color; | ||
import android.content.Context; | ||
|
||
public class HeaderColor extends CordovaPlugin { | ||
@Override | ||
public void initialize(final CordovaInterface cordova, CordovaWebView webView){ | ||
super.initialize(cordova, webView); | ||
setColor(preferences.getString("HeaderColor", "#000000")); | ||
} | ||
|
||
@Override | ||
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { | ||
if (action.equals("tint")) { | ||
int color = Color.parseColor(data.getString(0)); | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
ActivityManager activityManager = (ActivityManager) cordova.getActivity().getSystemService(Context.ACTIVITY_SERVICE); | ||
for(ActivityManager.AppTask appTask : activityManager.getAppTasks()) { | ||
if(appTask.getTaskInfo().id == cordova.getActivity().getTaskId()) { | ||
ActivityManager.TaskDescription description = appTask.getTaskInfo().taskDescription; | ||
cordova.getActivity().setTaskDescription(new ActivityManager.TaskDescription(description.getLabel(), description.getIcon(), color)); | ||
} | ||
} | ||
|
||
} | ||
} | ||
return false; | ||
if (action.equals("tint")) { | ||
setColor(data.getString(0)); | ||
} | ||
return false; | ||
} | ||
|
||
private void setColor(String data) { | ||
int color = Color.parseColor(data); | ||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
ActivityManager activityManager = (ActivityManager) cordova.getActivity().getSystemService(Context.ACTIVITY_SERVICE); | ||
for(ActivityManager.AppTask appTask : activityManager.getAppTasks()) { | ||
if(appTask.getTaskInfo().id == cordova.getActivity().getTaskId()) { | ||
ActivityManager.TaskDescription description = appTask.getTaskInfo().taskDescription; | ||
cordova.getActivity().setTaskDescription(new ActivityManager.TaskDescription(description.getLabel(), description.getIcon(), color)); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |