protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { this.visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey"); } else { Intent intent = getIntent(); if (intent.hasExtra(SHOW_LEAK_EXTRA)) { this.visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA); } } this.leaks = (List) getLastNonConfigurationInstance(); setContentView(R.layout.__leak_canary_display_leak); this.listView = (ListView) findViewById(R.id.__leak_canary_display_leak_list); this.failureView = (TextView) findViewById(R.id.__leak_canary_display_leak_failure); this.actionButton = (Button) findViewById(R.id.__leak_canary_action); this.maxStoredLeaks = getResources().getInteger(R.integer.__leak_canary_max_stored_leaks); updateUi(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey"); } else { Intent intent = getIntent(); if (intent.hasExtra(SHOW_LEAK_EXTRA)) { visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA); } } //noinspection unchecked leaks = (List<Leak>) getLastNonConfigurationInstance(); setContentView(R.layout.leak_canary_display_leak); listView = (ListView) findViewById(R.id.leak_canary_display_leak_list); failureView = (TextView) findViewById(R.id.leak_canary_display_leak_failure); actionButton = (Button) findViewById(R.id.leak_canary_action); updateUi(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey"); } else { Intent intent = getIntent(); if (intent.hasExtra(SHOW_LEAK_EXTRA)) { visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA); } } // noinspection unchecked leaks = (List<Leak>) getLastNonConfigurationInstance(); setContentView(R.layout.leak_canary_display_leak); listView = (ListView) findViewById(R.id.leak_canary_display_leak_list); failureView = (TextView) findViewById(R.id.leak_canary_display_leak_failure); actionButton = (Button) findViewById(R.id.leak_canary_action); updateUi(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(DisplayLeakActivity.this) .inflate(R.layout.__leak_canary_leak_row, parent, false); } TextView titleView = (TextView) convertView.findViewById(R.id.__leak_canary_row_text); TextView timeView = (TextView) convertView.findViewById(R.id.__leak_canary_row_time); Leak leak = getItem(position); String index; if (position == 0 && leaks.size() == maxStoredLeaks) { index = "MAX. "; } else { index = (leaks.size() - position) + ". "; } String title = index + getString(R.string.__leak_canary_class_has_leaked, classSimpleName(leak.result.className)); titleView.setText(title); String time = DateUtils.formatDateTime(DisplayLeakActivity.this, leak.heapDump.heapDumpFile.lastModified(), FORMAT_SHOW_TIME | FORMAT_SHOW_DATE); timeView.setText(time); return convertView; }
public static void showNotification(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent pendingIntent, int notificationId) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification; Notification.Builder builder = new Notification.Builder(context) // .setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setContentTitle(contentTitle) .setContentText(contentText) .setAutoCancel(true) .setContentIntent(pendingIntent); if (SDK_INT >= O) { String channelName = context.getString(R.string.leak_canary_notification_channel); setupNotificationChannel(channelName, notificationManager, builder); } if (SDK_INT < JELLY_BEAN) { notification = builder.getNotification(); } else { notification = builder.build(); } notificationManager.notify(notificationId, notification); }
@SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey"); } else { Intent intent = getIntent(); if (intent.hasExtra(SHOW_LEAK_EXTRA)) { visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA); } } leaks = (List<Leak>) getLastNonConfigurationInstance(); setContentView(R.layout.leak_canary_display_leak); listView = (ListView) findViewById(R.id.leak_canary_display_leak_list); failureView = (TextView) findViewById(R.id.leak_canary_display_leak_failure); actionButton = (Button) findViewById(R.id.leak_canary_action); updateUi(); }
public View getView(int position, View convertView, ViewGroup parent) { String index; String title; if (convertView == null) { convertView = LayoutInflater.from(DisplayLeakActivity.this).inflate(R.layout .__leak_canary_leak_row, parent, false); } TextView titleView = (TextView) convertView.findViewById(R.id.__leak_canary_row_text); TextView timeView = (TextView) convertView.findViewById(R.id.__leak_canary_row_time); Leak leak = getItem(position); if (position == 0 && DisplayLeakActivity.this.leaks.size() == DisplayLeakActivity .this.maxStoredLeaks) { index = "MAX. "; } else { index = (DisplayLeakActivity.this.leaks.size() - position) + ". "; } if (leak.result.failure == null) { title = index + DisplayLeakActivity.this.getString(R.string .__leak_canary_class_has_leaked, new Object[]{DisplayLeakActivity .classSimpleName(leak.result.className)}); } else { title = index + leak.result.failure.getClass().getSimpleName() + " " + leak .result.failure.getMessage(); } titleView.setText(title); timeView.setText(DateUtils.formatDateTime(DisplayLeakActivity.this, leak.heapDump .heapDumpFile.lastModified(), 17)); return convertView; }
private void shareLeak() { Leak visibleLeak = getVisibleLeak(); String leakInfo = LeakCanary.leakInfo(this, visibleLeak.heapDump, visibleLeak.result, true); Intent intent = new Intent("android.intent.action.SEND"); intent.setType("text/plain"); intent.putExtra("android.intent.extra.TEXT", leakInfo); startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with))); }
private void shareHeapDump() { File heapDumpFile = getVisibleLeak().heapDump.heapDumpFile; heapDumpFile.setReadable(true, false); Intent intent = new Intent("android.intent.action.SEND"); intent.setType("application/octet-stream"); intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(heapDumpFile)); startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with))); }
@TargetApi(HONEYCOMB) public static void showNotification(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent pendingIntent) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification; if (SDK_INT < HONEYCOMB) { notification = new Notification(); notification.icon = R.drawable.leak_canary_notification; notification.when = System.currentTimeMillis(); notification.flags |= Notification.FLAG_AUTO_CANCEL; try { Method method = Notification.class.getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class); method.invoke(notification, context, contentTitle, contentText, pendingIntent); } catch (Exception e) { throw new RuntimeException(e); } } else { Notification.Builder builder = new Notification.Builder(context) // .setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setContentTitle(contentTitle) .setContentText(contentText) .setAutoCancel(true) .setContentIntent(pendingIntent); if (SDK_INT < JELLY_BEAN) { notification = builder.getNotification(); } else { notification = builder.build(); } } notificationManager.notify(0xDEAFBEEF, notification); }
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (!hasStoragePermission()) { Toast.makeText(getApplication(), R.string.leak_canary_permission_not_granted, LENGTH_LONG) .show(); } finish(); }
@Override public void setTheme(int resid) { // We don't want this to be called with an incompatible theme. // This could happen if you implement runtime switching of themes // using ActivityLifecycleCallbacks. if (resid != R.style.leak_canary_LeakCanary_Base) { return; } super.setTheme(resid); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { visibleLeakRefKey = null; updateUi(); } return true; }
void shareLeak() { Leak visibleLeak = getVisibleLeak(); String leakInfo = leakInfo(this, visibleLeak.heapDump, visibleLeak.result, true); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, leakInfo); startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with))); }
void shareHeapDump() { Leak visibleLeak = getVisibleLeak(); File heapDumpFile = visibleLeak.heapDump.heapDumpFile; heapDumpFile.setReadable(true, false); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(heapDumpFile)); startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with))); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); View button = findViewById(R.id.async_task); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startAsyncTask(); } }); }
@SuppressWarnings({ "deprecation", "unchecked" }) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey"); } else { Intent intent = getIntent(); if (intent.hasExtra(SHOW_LEAK_EXTRA)) { visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA); } } // noinspection unchecked leaks = (List<Leak>) getLastNonConfigurationInstance(); setContentView(R.layout.__leak_canary_display_leak); listView = (ListView) findViewById(R.id.__leak_canary_display_leak_list); actionButton = (Button) findViewById(R.id.__leak_canary_action); maxStoredLeaks = getResources().getInteger(R.integer.__leak_canary_max_stored_leaks); updateUi(); }
private void shareLeak() { Leak visibleLeak = getVisibleLeak(); String leakInfo = leakInfo(this, visibleLeak.heapDump, visibleLeak.result); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, leakInfo); startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with))); }
private void shareHeapDump() { Leak visibleLeak = getVisibleLeak(); File heapDumpFile = visibleLeak.heapDump.heapDumpFile; heapDumpFile.setReadable(true, false); Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(heapDumpFile)); startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with))); }
public View getView(int position, View convertView, ViewGroup parent) { Context context = parent.getContext(); if (getItemViewType(position) == 0) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout .__leak_canary_ref_top_row, parent, false); } ((TextView) findById(convertView, R.id.__leak_canary_row_text)).setText(context .getPackageName()); } else { boolean isRoot; boolean isLeakingInstance; if (convertView == null) { convertView = LayoutInflater.from(context).inflate(R.layout .__leak_canary_ref_row, parent, false); } TextView textView = (TextView) findById(convertView, R.id.__leak_canary_row_text); if (position == 1) { isRoot = true; } else { isRoot = false; } if (position == getCount() - 1) { isLeakingInstance = true; } else { isLeakingInstance = false; } String htmlString = elementToHtmlString(getItem(position), isRoot, this .opened[position]); if (isLeakingInstance && !this.referenceName.equals("") && this.opened[position]) { htmlString = htmlString + " <font color='#919191'>" + this.referenceName + "</font>"; } textView.setText(Html.fromHtml(htmlString)); DisplayLeakConnectorView connector = (DisplayLeakConnectorView) findById(convertView, R.id.__leak_canary_row_connector); if (isRoot) { connector.setType(Type.START); } else if (isLeakingInstance) { connector.setType(Type.END); } else { connector.setType(Type.NODE); } ((MoreDetailsView) findById(convertView, R.id.__leak_canary_row_more)).setOpened(this .opened[position]); } return convertView; }