Launcher icon Theming - android

guyz i need a little help again with the launcher icon theming :p
this is the method that changes icon in LauncherModel.java in ADWLauncher
static Drawable getIcon(PackageManager manager, Context context, ActivityInfo activityInfo) {
String themePackage=AlmostNexusSettingsHelper.getThemePackageName(context, Launcher.THEME_DEFAULT);
Drawable icon = null;
if(themePackage.equals(Launcher.THEME_DEFAULT)){
icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context);
}else{
// get from theme
Resources themeResources = null;
if(AlmostNexusSettingsHelper.getThemeIcons(context)){
activityInfo.name=activityInfo.name.toLowerCase().replace(".", "_");
try {
themeResources = manager.getResourcesForApplication(themePackage);
} catch (NameNotFoundException e) {
//e.printStackTrace();
}
if(themeResources!=null){
int resource_id = themeResources.getIdentifier(activityInfo.name, "drawable", themePackage);
if(resource_id!=0){
icon=themeResources.getDrawable(resource_id);
}
// use IconShader
if(icon==null){
if (compiledIconShaderName==null ||
compiledIconShaderName.compareTo(themePackage)!=0){
compiledIconShader = null;
resource_id = themeResources.getIdentifier("shader", "xml", themePackage);
if(resource_id!=0){
XmlResourceParser xpp = themeResources.getXml(resource_id);
compiledIconShader = IconShader.parseXml(xpp);
}
}
if(compiledIconShader!=null){
icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context);
try {
icon = IconShader.processIcon(icon, compiledIconShader);
} catch (Exception e) {}
}
}
}
}
if(icon==null){
icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context);
}else{
icon = Utilities.createIconThumbnail(icon, context);
}
}
return icon;
}
but there is no such method in the LauncherModel, instead it is inside IconCache (which is not in the ADWLauncher) (https://android.googlesource.com/platform/packages/apps/Launcher2/+/master/src/com/android/launcher2/IconCache.java)
how can i edit iconcache.java to implement that??

If you want to change your launcher icon you should check out my project that just just that. https://github.com/slightfoot/android-launcher-badges

Related

EditText checking

I'm trying to check an EditText value, but the application crashes.
How can I handle my EditText?
String stra_txt = edit_1.getText().toString();
boolean first = false;
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
first = true;
}
else
{
first = false;
}
if(first = true)
zheg();
else
{System.exit(0);}
this code does not work too:
String stra_txt = edit_1.getText().toString();
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
zheg();
}
else
{
System.exit(0);
}
upd.
I've found solution:
if (edit_1.getText().toString().equals("")){
finish();
}
else
{
zheg();
}
Use try Catch Block its get actual error or app crash
try
{
String stra_txt = edit_1.getText().toString();
boolean first = false;
boolean second = false;
if (stra_txt.equals("1") || stra_txt.equals("0"))
{
first = true;
}
else
{
first = false;
}
if(first = true)
zheg();
else
{System.exit(0);}
}
catch (Exception e)
{
e.printStackTrace();
}
Check whether you have linked your EditText id with XML
EditText edit_1 = (EditText) findViewById(R.id.edit_1);
if you have given this, then there must be a problem with zheg() method.
Please post your logs here.
Try this code
if(edit_1 != null){
String stra_txt = edit_1.getText().toString();
if ((stra_txt.equals("1") || stra_txt.equals("0")){
zheg();
}else{
// System.exit(0);
finish();
}
}
if this prevents your app from getting crashed then probably you may not be initializing the view. Add this line before the above code:
edit_1 = (EditText)findViewById(YOUR_VIEW_ID);

appcompat-v7 v23.0.0 statusbar color black when in ActionMode

UPDATE
Same issue present in the latest Gmail app. I still don't understand why would Google make such unpleasant UI change. Obsessive in me goes crazy whenever I see it
QUESTION
I have this weird issue with appcompat-v7 23. Issue I am going to describe does not happen with 22 series
You can get source code that reproduces this issuse form
https://github.com/devserv/t/
Once built, you can tap and hold an item in the list to activate ActionMode
Issue:
When in ActionMode, appcompat turns status bar to black. This does not happen if I don’t use following
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
in my v21 style but I have to use it because I want my navigation drawer to look behind status bar.
I used to use following to avoid black status bar when ActionMode started and ended
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.appColorPrimaryDark));
}
}
public void onDestroyActionMode(ActionMode actionMode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActivity().getWindow().setStatusBarColor(getResources().getColor(android.R.color.transparent));
}
mMode = null;
}
Above code did not create/avoided status bar turning black, but does not work properly on v23 of appcompat. Instead you see a short black status bar while ActionMode destroyed. It looks like related to the animation that plays when ActionMode destroyed.
I have tried to open bug reports but it has been declined with comment
Don't re-create bugs.
Am I missing something?
Here are the screenshots for normal and action mode.
In case only the color is the issue, you can change it. Only to a fixed color resource.
<color name="abc_input_method_navigation_guard" tools:override="true">#color/primary_dark</color>
Obvious ?colorPrimaryDark will not work, not even on API 21.
The view responsible for the black status bar background is stored in AppCompatDelegateImplV7.mStatusGuard. You can get the delegate by calling getDelegate() from your activity and access mStatusGuard field by reflection. After starting the action mode you can get a reference to this view and customize it however you like.
This was found in AppCompat 24.1.1.
The version 23.0.0 of v7 appcompat library introduced an animation that fades in and out the action mode when it's started and finished as you can read here:
The action mode has fades in and is working as intended.
The changes are made in the method onDestroyActionMode in AppCompatDelegateImplV7:
public void onDestroyActionMode(ActionMode mode) {
mWrapped.onDestroyActionMode(mode);
if (mActionModePopup != null) {
mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
mActionModePopup.dismiss();
} else if (mActionModeView != null) {
mActionModeView.setVisibility(View.GONE);
if (mActionModeView.getParent() != null) {
ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
}
}
if (mActionModeView != null) {
mActionModeView.removeAllViews();
}
if (mAppCompatCallback != null) {
mAppCompatCallback.onSupportActionModeFinished(mActionMode);
}
mActionMode = null;
}
In version 23.0.0 it was changed to:
public void onDestroyActionMode(ActionMode mode) {
mWrapped.onDestroyActionMode(mode);
if (mActionModePopup != null) {
mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
}
if (mActionModeView != null) {
endOnGoingFadeAnimation();
mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0f);
mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() {
#Override
public void onAnimationEnd(View view) {
mActionModeView.setVisibility(View.GONE);
if (mActionModePopup != null) {
mActionModePopup.dismiss();
} else if (mActionModeView.getParent() instanceof View) {
ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
}
mActionModeView.removeAllViews();
mFadeAnim.setListener(null);
mFadeAnim = null;
}
});
}
if (mAppCompatCallback != null) {
mAppCompatCallback.onSupportActionModeFinished(mActionMode);
}
mActionMode = null;
}
As you can see mWrapped.onDestroyActionMode(mode); is called immediately, not when the animation ends. This is what cause the black status bar in your app and in other apps like Gmail and Keep.
The workaround that you found works, but unfortunately is not reliable, because if the animation takes longer you could see the black status bar anyway.
I think Google should correct the issue and call onDestroyActionMode only when the animation is really ended. In the mean time you can change this behaviour with a bit of reflections. It is necessary to override onSupportActionModeStarted in your activity and call the method fixActionModeCallback:
#Override
public void onSupportActionModeStarted(ActionMode mode) {
super.onSupportActionModeStarted(mode);
//Call this method
fixActionModeCallback(this, mode);
}
private void fixActionModeCallback(AppCompatActivity activity, ActionMode mode) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
if (!(mode instanceof StandaloneActionMode))
return;
try {
final Field mCallbackField = mode.getClass().getDeclaredField("mCallback");
mCallbackField.setAccessible(true);
final Object mCallback = mCallbackField.get(mode);
final Field mWrappedField = mCallback.getClass().getDeclaredField("mWrapped");
mWrappedField.setAccessible(true);
final ActionMode.Callback mWrapped = (ActionMode.Callback) mWrappedField.get(mCallback);
final Field mDelegateField = AppCompatActivity.class.getDeclaredField("mDelegate");
mDelegateField.setAccessible(true);
final Object mDelegate = mDelegateField.get(activity);
mCallbackField.set(mode, new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
return mWrapped.onCreateActionMode(mode, menu);
}
#Override
public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
return mWrapped.onPrepareActionMode(mode, menu);
}
#Override
public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
return mWrapped.onActionItemClicked(mode, item);
}
#Override
public void onDestroyActionMode(final android.support.v7.view.ActionMode mode) {
Class mDelegateClass = mDelegate.getClass().getSuperclass();
Window mWindow = null;
PopupWindow mActionModePopup = null;
Runnable mShowActionModePopup = null;
ActionBarContextView mActionModeView = null;
AppCompatCallback mAppCompatCallback = null;
ViewPropertyAnimatorCompat mFadeAnim = null;
android.support.v7.view.ActionMode mActionMode = null;
Field mFadeAnimField = null;
Field mActionModeField = null;
while (mDelegateClass != null) {
try {
if (TextUtils.equals("AppCompatDelegateImplV7", mDelegateClass.getSimpleName())) {
Field mActionModePopupField = mDelegateClass.getDeclaredField("mActionModePopup");
mActionModePopupField.setAccessible(true);
mActionModePopup = (PopupWindow) mActionModePopupField.get(mDelegate);
Field mShowActionModePopupField = mDelegateClass.getDeclaredField("mShowActionModePopup");
mShowActionModePopupField.setAccessible(true);
mShowActionModePopup = (Runnable) mShowActionModePopupField.get(mDelegate);
Field mActionModeViewField = mDelegateClass.getDeclaredField("mActionModeView");
mActionModeViewField.setAccessible(true);
mActionModeView = (ActionBarContextView) mActionModeViewField.get(mDelegate);
mFadeAnimField = mDelegateClass.getDeclaredField("mFadeAnim");
mFadeAnimField.setAccessible(true);
mFadeAnim = (ViewPropertyAnimatorCompat) mFadeAnimField.get(mDelegate);
mActionModeField = mDelegateClass.getDeclaredField("mActionMode");
mActionModeField.setAccessible(true);
mActionMode = (android.support.v7.view.ActionMode) mActionModeField.get(mDelegate);
} else if (TextUtils.equals("AppCompatDelegateImplBase", mDelegateClass.getSimpleName())) {
Field mAppCompatCallbackField = mDelegateClass.getDeclaredField("mAppCompatCallback");
mAppCompatCallbackField.setAccessible(true);
mAppCompatCallback = (AppCompatCallback) mAppCompatCallbackField.get(mDelegate);
Field mWindowField = mDelegateClass.getDeclaredField("mWindow");
mWindowField.setAccessible(true);
mWindow = (Window) mWindowField.get(mDelegate);
}
mDelegateClass = mDelegateClass.getSuperclass();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
if (mActionModePopup != null) {
mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
}
if (mActionModeView != null) {
if (mFadeAnim != null) {
mFadeAnim.cancel();
}
mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0.0F);
final PopupWindow mActionModePopupFinal = mActionModePopup;
final ActionBarContextView mActionModeViewFinal = mActionModeView;
final ViewPropertyAnimatorCompat mFadeAnimFinal = mFadeAnim;
final AppCompatCallback mAppCompatCallbackFinal = mAppCompatCallback;
final android.support.v7.view.ActionMode mActionModeFinal = mActionMode;
final Field mFadeAnimFieldFinal = mFadeAnimField;
final Field mActionModeFieldFinal = mActionModeField;
mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() {
public void onAnimationEnd(View view) {
mActionModeViewFinal.setVisibility(View.GONE);
if (mActionModePopupFinal != null) {
mActionModePopupFinal.dismiss();
} else if (mActionModeViewFinal.getParent() instanceof View) {
ViewCompat.requestApplyInsets((View) mActionModeViewFinal.getParent());
}
mActionModeViewFinal.removeAllViews();
mFadeAnimFinal.setListener((ViewPropertyAnimatorListener) null);
try {
if (mFadeAnimFieldFinal != null) {
mFadeAnimFieldFinal.set(mDelegate, null);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mWrapped.onDestroyActionMode(mode);
if (mAppCompatCallbackFinal != null) {
mAppCompatCallbackFinal.onSupportActionModeFinished(mActionModeFinal);
}
try {
if (mActionModeFieldFinal != null) {
mActionModeFieldFinal.set(mDelegate, null);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
});
}
}
});
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
Nobody? Here is the workaround I came up with. Delay.
#Override
public void onDestroyActionMode(ActionMode mode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
try {
getActivity().getWindow().setStatusBarColor(getResources().getColor(android.R.color.transparent));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}, 400);
}
mActionMode = null;
}

I am not able to display notification count on application icon in home screen

Hello I want to display notification count on application icon in home screen but I am not able to do this.
This is my code.
public class MainActivity extends Activity {
ImageView img;
BadgeView badge;
public int badgeCount;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
badgeCount = 0;
img = (ImageView)findViewById(R.id.notificationicon);
Drawable icon;
try {
icon = getPackageManager().getApplicationIcon("com.example.notificationapp");
img.setImageDrawable(icon);
badge = new BadgeView(this, img);
badge.setText("10");
} catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
badge = new BadgeView(this, img);
badge.setText("10");
badgeCount = Integer.parseInt("5");
ShortcutBadger.with(getApplicationContext()).count(badgeCount);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (badge.isShown()) {
try {
badgeCount = Integer.parseInt("5");
} catch (NumberFormatException e) {
Toast.makeText(getApplicationContext(), "Error input", Toast.LENGTH_SHORT).show();
}
// ShortcutBadger.setBadge(getApplicationContext(), badgeCount);
ShortcutBadger.with(getApplicationContext()).count(badgeCount);
Toast.makeText(getApplicationContext(), "Set count=" + badgeCount, Toast.LENGTH_SHORT).show();
badge.decrement(1);
} else {
// badge.decrement(1);
badge.show();
}
}
});
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentHomePackage = resolveInfo.activityInfo.packageName;
ShortcutBadger.with(getApplicationContext()).count(badgeCount);
TextView textViewHomePackage = (TextView) findViewById(R.id.textViewHomePackage);
textViewHomePackage.setText("launcher:" + currentHomePackage);
}
used this two line code to set notification count on app icon .
ShortcutBadger.setBadge(getApplicationContext(), badgeCount);
ShortcutBadger.with(getApplicationContext()).count(badgeCount);
But with this I am not able to do this.
ShortcutBadger only supports some third party launchers.
It does not support the stock Android launcher which is on many devices and the emulator.

GoogleMap markers weird behaviour

This is a strange one and I hope that someone can at least give me a direction to look in.
My Android application uses GoogleMap API v2. In the app, I run an activity off OnClickInfoWindowListener on one of the markers. In detail, when I click on the particular marker, an InfoWindow of that marker appears. Next when I click on the InfoWindow, it launches another activity.
The problem is that when I return to GoogleMap from that activity, the particular marker which launched the activity, is not responsive. By responsive, I mean when I click on it, I do not get an InfoWindow. There is no such problem with the other markers. To fix the problem, I either move or zoom on the map or click on another marker to show its InfoWindow, then the original marker works normally. I cannot see any red stuff on the LogCat.
I also run the map off a ListView and there is no problem (that I can see).
Any suggestions on what to look at are very welcome!
Edit 1 :
This part is the InfoWindowClickListener setup ...
// Set up info Window Click Listener
googleMap
.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
#Override
public void onInfoWindowClick(Marker mkr) {
// Default open file
// menu option : edit file information
// menu option : delete
Log.d(TAG, "InfoWindow Click detected.");
final GeoFileData gfd = getFromHashMap(mkr);
if (editGeoFile) {
editGeoFile = false;
editFileInfo(gfd);
} else if (deleteGeoFile) {
deleteGeoFile = false;
deleteFile(gfd, mkr);
} else {
openFile(gfd);
}
}
});
The openFile routine which launches the Activity
// Public and Routines used by the main loop
private void openFile (GeoFileData gfd) {
int typeIndex = gfd.getTypeIndex();
switch(typeIndex) {
case 0 :
case 1 :
case 2 :
case 3 :
// Spen file by default
Intent notePadIntent = new Intent(getBaseContext(), NotePad.class);
Bundle b = new Bundle();
b.putParcelable(MAIN_NOTEPAD_GFD, gfd);
notePadIntent.putExtras(b);
startActivityForResult(notePadIntent, SPEN_NOTEPAD_CODE);
break;
default :
Log.w(TAG, "Unknown file.");
Toast.makeText(this, getString(R.string.toast_unknown_file), Toast.LENGTH_LONG).show();
break;
}
}
The starting part of the launched activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spen_notepad);
Bundle extras = getIntent().getExtras();
if (extras != null) {
inputGfd = extras.getParcelable(PreznsActivity.MAIN_NOTEPAD_GFD);
}
extras.clear();
mContext = this;
// Spen
boolean isSpenFeatureEnabled = false;
Spen spenPackage = new Spen();
try {
spenPackage.initialize(this);
isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
} catch (SsdkUnsupportedException e) {
if( SDKUtils.processUnsupportedException(this, e) == true) {
return;
}
} catch (Exception e1) {
Toast.makeText(mContext, "Cannot initialize Spen.",
Toast.LENGTH_SHORT).show();
e1.printStackTrace();
finish();
}
FrameLayout spenViewContainer =
(FrameLayout) findViewById(R.id.spenViewContainer);
RelativeLayout spenViewLayout =
(RelativeLayout) findViewById(R.id.spenViewLayout);
// PenSettingView
mPenSettingView =
new SpenSettingPenLayout(mContext, new String(),
spenViewLayout);
if (mPenSettingView == null) {
Toast.makeText(mContext, "Cannot create new PenSettingView.",
Toast.LENGTH_SHORT).show();
finish();
}
// EraserSettingView
mEraserSettingView =
new SpenSettingEraserLayout(mContext, new String(),
spenViewLayout);
if (mEraserSettingView == null) {
Toast.makeText(mContext, "Cannot create new EraserSettingView.",
Toast.LENGTH_SHORT).show();
finish();
}
// TextSettingView
mTextSettingView = new SpenSettingTextLayout(mContext, new String(), new HashMap<String, String>(), spenViewLayout);
if (mTextSettingView == null) {
Toast.makeText(mContext, "Cannot craeate new TextSettingView.", Toast.LENGTH_SHORT).show();
finish();
}
spenViewContainer.addView(mPenSettingView);
spenViewContainer.addView(mEraserSettingView);
spenViewContainer.addView(mTextSettingView);
// SpenSurfaceView
mSpenSurfaceView = new SpenSurfaceView(mContext);
if (mSpenSurfaceView == null) {
Toast.makeText(mContext, "Cannot create new SpenSurfaceView.",
Toast.LENGTH_SHORT).show();
finish();
}
spenViewLayout.addView(mSpenSurfaceView);
mPenSettingView.setCanvasView(mSpenSurfaceView);
mEraserSettingView.setCanvasView(mSpenSurfaceView);
mTextSettingView.setCanvasView(mSpenSurfaceView);
//
Display display = getWindowManager().getDefaultDisplay();
mScreenRect = new Rect();
display.getRectSize(mScreenRect);
// SpenNoteDoc
try {
mSpenNoteDoc =
new SpenNoteDoc(mContext, mScreenRect.width(), mScreenRect.height());
} catch (IOException e) {
Toast.makeText(mContext, "Cannot create new NoteDoc",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
finish();
} catch (Exception e) {
e.printStackTrace();
finish();
}
// NoteDoc
mSpenPageDoc = mSpenNoteDoc.appendPage();
mSpenPageDoc.setBackgroundColor(0xFFD6E6F5);
mSpenPageDoc.clearHistory();
// PageDoc
mSpenSurfaceView.setPageDoc(mSpenPageDoc, true);
initSettingInfo();
// Listener
mSpenSurfaceView.setTouchListener(mPenTouchListener);
mSpenSurfaceView.setColorPickerListener(mColorPickerListener);
mSpenSurfaceView.setTextChangeListener(mTextChangeListener);
mSpenSurfaceView.setReplayListener(mReplayListener);
mSpenPageDoc.setHistoryListener(mHistoryListener);
mEraserSettingView.setEraserListener(mEraserListener);
mSpenSurfaceView.setFlickListener(mFlickListener);
// Button
mTextObjBtn = (ImageView) findViewById(R.id.textObjBtn);
mTextObjBtn.setOnClickListener(mTextObjBtnClickListener);
mPenBtn = (ImageView) findViewById(R.id.penBtn);
mPenBtn.setOnClickListener(mPenBtnClickListener);
mEraserBtn = (ImageView) findViewById(R.id.eraserBtn);
mEraserBtn.setOnClickListener(mEraserBtnClickListener);
mUndoBtn = (ImageView) findViewById(R.id.undoBtn);
mUndoBtn.setOnClickListener(undoNredoBtnClickListener);
mUndoBtn.setEnabled(mSpenPageDoc.isUndoable());
mRedoBtn = (ImageView) findViewById(R.id.redoBtn);
mRedoBtn.setOnClickListener(undoNredoBtnClickListener);
mRedoBtn.setEnabled(mSpenPageDoc.isRedoable());
mImgObjBtn = (ImageView) findViewById(R.id.imgObjBtn);
mImgObjBtn.setOnClickListener(mImgObjBtnClickListener);
mAddPageBtn = (ImageView) findViewById(R.id.addPageBtn);
mAddPageBtn.setOnClickListener(mAddPageBtnClickListener);
mTxtView = (TextView) findViewById(R.id.spen_page);
mTxtView.setText("Page" + mSpenNoteDoc.getPageIndexById(mSpenPageDoc.getId()));
selectButton(mPenBtn);
String filePath = inputGfd.getFileDirectory();
mFilePath = new File(filePath);
if (!mFilePath.exists()) {
if (!mFilePath.mkdirs()) {
Toast.makeText(mContext, "Save Path Creation Error", Toast.LENGTH_SHORT).show();
return;
}
}
mSpenPageDoc.startRecord();
File loadFile = new File(inputGfd.getFileDirectory(), inputGfd.getFileName());
if (loadFile.exists()) {
loadNoteFile();
} else {
Log.w(TAG, "File does not exist!");
}
if(isSpenFeatureEnabled == false) {
mToolType = SpenSurfaceView.TOOL_FINGER;
mSpenSurfaceView.setToolTypeAction(mToolType,
SpenSurfaceView.ACTION_STROKE);
Toast.makeText(mContext,
"Device does not support Spen. \n You can draw stroke by finger",
Toast.LENGTH_SHORT).show();
}
}
One of the returns for the activity
private boolean saveNoteFile(final boolean isClose) {
// file save
// note file
String saveFilePath = inputGfd.getFileDirectory() + File.separator;
String fileName = inputGfd.getFileName();
if (!fileName.equals("")) {
saveFilePath += fileName;
saveNoteFile(saveFilePath);
if (isClose)
finish();
} else {
Toast
.makeText(mContext, "Invalid filename !!!", Toast.LENGTH_LONG)
.show();
}
return true;
}
and finally the destroy routine,
#Override
protected void onDestroy() {
Log.d(TAG, "NotePad onDestroy()");
super.onDestroy();
if (mSpenNoteDoc != null && mSpenPageDoc.isRecording()) {
mSpenPageDoc.stopRecord();
}
if (mPenSettingView != null) {
mPenSettingView.close();
}
if (mEraserSettingView != null) {
mEraserSettingView.close();
}
if (mTextSettingView != null) {
mTextSettingView.close();
}
if(mSpenSurfaceView != null) {
if (mSpenSurfaceView.getReplayState() == SpenSurfaceView.REPLAY_STATE_PLAYING) {
mSpenSurfaceView.stopReplay();
}
mSpenSurfaceView.closeControl();
mSpenSurfaceView.close();
mSpenSurfaceView = null;
}
if(mSpenNoteDoc != null) {
try {
if (isDiscard)
mSpenNoteDoc.discard();
else
mSpenNoteDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
mSpenNoteDoc = null;
}
};
Thanks!
This is likely a bug in Google Maps Android API v2 itself.
I encounter it in my app. When you open "Declusterification" demo, click on yellow marker with 10 in the center and a new marker (red default) appears in the same spot, this new marker cannot be interacted with to show info window without moving the map.
If you happen to figure out SSCCE for it, I suggest posting it on gmaps-api-issues. I'll support it. If I do find simple example to show this issue, I'll also post an update here.
To close up this question.
GoogleMap markers exhibit the anomalies mentioned in this thread and currently the issue has been fed back to Google. There are two apparent "workarounds" to the problem but how effective they are is not clear:
1st workaround : work within the limitations of .clear(). An activated marker cannot be deactivated with .clear().
2nd workaround : after returning from the activity, perform a camera update. This apparently resets the activation of the marker.

Getting App Icon in Android

I'm having some trouble retrieving icons for installed Android App. The following code returns icons for all apps, however, some apps are returned with small icons (perhaps from drawable - ldpi folder) while some with large icons.
List<PackageInfo> package = getPackageManager().getInstalledPackages(0);
for(PackageInfo p : package){
iApp.icon = p.applicationInfo.loadIcon(getPackageManager());
}
How Can I get icons which are all of the same size, just like in Manage Application section of Android?
I want to add something to previous answer what applies to Android 3.0 and greater.
You can notice that icons retrieved in this standard way (i mean applicationInfo.loadIcon and other typical methods) are smaller than icons you see in launcher app. Scale up just makes icons blurrier. If you want big icons you can use next code (i took it from launcher source code you can find here and changed a bit). Pay your attention to activityManager.getLauncherLargeIconDensity method.
public Drawable getFullResDefaultActivityIcon() {
return getFullResIcon(Resources.getSystem(), android.R.mipmap.sym_def_app_icon);
}
public Drawable getFullResIcon(Resources resources, int iconId) {
Drawable d;
try {
ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
int iconDpi = activityManager.getLauncherLargeIconDensity();
d = resources.getDrawableForDensity(iconId, iconDpi);
} catch (Resources.NotFoundException e) {
d = null;
}
return (d != null) ? d : getFullResDefaultActivityIcon();
}
public Drawable getFullResIcon(String packageName, int iconId) {
Resources resources;
try {
resources = mContext.getPackageManager().getResourcesForApplication(packageName);
} catch (PackageManager.NameNotFoundException e) {
resources = null;
}
if (resources != null) {
if (iconId != 0) {
return getFullResIcon(resources, iconId);
}
}
return getFullResDefaultActivityIcon();
}
public Drawable getFullResIcon(ResolveInfo info) {
return getFullResIcon(info.activityInfo);
}
public Drawable getFullResIcon(ActivityInfo info) {
Resources resources;
try {
resources = mContext.getPackageManager().getResourcesForApplication(info.applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
resources = null;
}
if (resources != null) {
int iconId = info.getIconResource();
if (iconId != 0) {
return getFullResIcon(resources, iconId);
}
}
return getFullResDefaultActivityIcon();
}
private Drawable getAppIcon(ResolveInfo info) {
return getFullResIcon(info.activityInfo);
}
Hope it helps someone.
Apps might just have different sized icons. The Android Settings app loads icons just like you. It scales the icons when displaying them.
Here's a snippet from packages/apps/Settings/res/layout/manage_applications_item.xml:
<ImageView android:id="#+id/app_icon"
android:layout_width="#android:dimen/app_icon_size"
android:layout_height="#android:dimen/app_icon_size"
android:layout_marginRight="11dip"
android:layout_gravity="center_vertical"
android:scaleType="fitCenter"/>
Although, this has been answered a long time back, here is the complete function. Hope it will help others.
To get the icon, you should query for icon for different dpi.
Try this:
public static Drawable getIconFromPackageName(String packageName, Context context)
{
PackageManager pm = context.getPackageManager();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
{
try
{
PackageInfo pi = pm.getPackageInfo(packageName, 0);
Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
int displayMetrics[] = {DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_TV};
for (int displayMetric : displayMetrics)
{
try
{
Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric);
if (d != null)
{
return d;
}
}
catch (Resources.NotFoundException e)
{
// Log.d(TAG, "NameNotFound for" + packageName + " # density: " + displayMetric);
continue;
}
}
}
catch (Exception e)
{
// Handle Error here
}
}
ApplicationInfo appInfo = null;
try
{
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
}
catch (PackageManager.NameNotFoundException e)
{
return null;
}
return appInfo.loadIcon(pm);
}
You must define in App class ;
private Drawable appIcon;
public Drawable getappIcon(){
return this.appIcon;
}
if you use RecyclerViewAdapter ;
List<App> list_app;
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.appIcon.setImageDrawable(list_app.get(position).getappIcon());
}
in MainActivity ;
private List<App> appList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
appList = new ArrayList<App>();
for (ApplicationInfo packageInfo : packages) {
Drawable drawableIcon =packageInfo.loadIcon(getPackageManager());
appList.add(new App (drawableIcon));
}

Categories

Resources