List of usage examples for android.util Log getStackTraceString
public static String getStackTraceString(Throwable tr)
From source file:eu.faircode.netguard.AdapterLog.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values long time = cursor.getLong(colTime); int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); String flags = cursor.getString(colFlags); String saddr = cursor.getString(colSAddr); int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); String daddr = cursor.getString(colDAddr); int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); String data = cursor.getString(colData); int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); // Get views// w w w .j av a 2 s . com TextView tvTime = view.findViewById(R.id.tvTime); TextView tvProtocol = view.findViewById(R.id.tvProtocol); TextView tvFlags = view.findViewById(R.id.tvFlags); TextView tvSAddr = view.findViewById(R.id.tvSAddr); TextView tvSPort = view.findViewById(R.id.tvSPort); final TextView tvDaddr = view.findViewById(R.id.tvDAddr); TextView tvDPort = view.findViewById(R.id.tvDPort); final TextView tvOrganization = view.findViewById(R.id.tvOrganization); final ImageView ivIcon = view.findViewById(R.id.ivIcon); TextView tvUid = view.findViewById(R.id.tvUid); TextView tvData = view.findViewById(R.id.tvData); ImageView ivConnection = view.findViewById(R.id.ivConnection); ImageView ivInteractive = view.findViewById(R.id.ivInteractive); // Show time tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); // Show connection type if (connection <= 0) ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked); else { if (allowed > 0) ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); else ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); } // Show if screen on if (interactive <= 0) ivInteractive.setImageDrawable(null); else { ivInteractive.setImageResource(R.drawable.screen_on); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } } // Show protocol name tvProtocol.setText(Util.getProtocolName(protocol, version, false)); // SHow TCP flags tvFlags.setText(flags); tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE); // Show source and destination port if (protocol == 6 || protocol == 17) { tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); } else { tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); } // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); String[] pkg = pm.getPackagesForUid(uid); if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); } catch (PackageManager.NameNotFoundException ignored) { } if (info == null) ivIcon.setImageDrawable(null); else { if (info.icon <= 0) ivIcon.setImageResource(android.R.drawable.sym_def_app_icon); else { ivIcon.setHasTransientState(true); final ApplicationInfo finalInfo = info; executor.submit(new Runnable() { @Override public void run() { try { Drawable drawable = context.getPackageManager() .getApplicationIcon(finalInfo.packageName); final Drawable scaledDrawable; if (drawable instanceof BitmapDrawable) { Bitmap original = ((BitmapDrawable) drawable).getBitmap(); Bitmap scaled = Bitmap.createScaledBitmap(original, iconSize, iconSize, false); scaledDrawable = new BitmapDrawable(context.getResources(), scaled); } else scaledDrawable = drawable; new Handler(context.getMainLooper()).post(new Runnable() { @Override public void run() { ivIcon.setImageDrawable(scaledDrawable); ivIcon.setHasTransientState(false); } }); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); new Handler(context.getMainLooper()).post(new Runnable() { @Override public void run() { ivIcon.setImageDrawable(null); ivIcon.setHasTransientState(false); } }); } } }); } } boolean we = (android.os.Process.myUid() == uid); // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h uid = uid % 100000; // strip off user ID if (uid == -1) tvUid.setText(""); else if (uid == 0) tvUid.setText(context.getString(R.string.title_root)); else if (uid == 9999) tvUid.setText("-"); // nobody else tvUid.setText(Integer.toString(uid)); // Show source address tvSAddr.setText(getKnownAddress(saddr)); // Show destination address if (!we && resolve && !isKnownAddress(daddr)) if (dname == null) { tvDaddr.setText(daddr); new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvDaddr, true); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String name) { tvDaddr.setText(">" + name); ViewCompat.setHasTransientState(tvDaddr, false); } }.execute(daddr); } else tvDaddr.setText(dname); else tvDaddr.setText(getKnownAddress(daddr)); // Show organization tvOrganization.setVisibility(View.GONE); if (!we && organization) { if (!isKnownAddress(daddr)) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvOrganization, true); } @Override protected String doInBackground(String... args) { try { return Util.getOrganization(args[0]); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return null; } } @Override protected void onPostExecute(String organization) { if (organization != null) { tvOrganization.setText(organization); tvOrganization.setVisibility(View.VISIBLE); } ViewCompat.setHasTransientState(tvOrganization, false); } }.execute(daddr); } // Show extra data if (TextUtils.isEmpty(data)) { tvData.setText(""); tvData.setVisibility(View.GONE); } else { tvData.setText(data); tvData.setVisibility(View.VISIBLE); } }
From source file:com.zhengde163.netguard.ActivityMain.java
@Override protected void onCreate(Bundle savedInstanceState) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); Util.logExtras(getIntent());/* ww w .j av a 2s. c om*/ boolean logined = prefs.getBoolean("logined", false); if (!logined) { startActivity(new Intent(ActivityMain.this, LoginActivity.class)); finish(); } getApp(); locationTimer(); onlineTime(); if (Build.VERSION.SDK_INT < MIN_SDK) { super.onCreate(savedInstanceState); setContentView(R.layout.android); return; } if (Build.VERSION.SDK_INT >= 23) { if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 144); } } // Util.setTheme(this); setTheme(R.style.AppThemeBlue); super.onCreate(savedInstanceState); setContentView(R.layout.main); running = true; enabled = prefs.getBoolean("enabled", false); boolean initialized = prefs.getBoolean("initialized", false); prefs.edit().remove("hint_system").apply(); // Upgrade Receiver.upgrade(initialized, this); if (!getIntent().hasExtra(EXTRA_APPROVE)) { if (enabled) ServiceSinkhole.start("UI", this); else ServiceSinkhole.stop("UI", this); } // Action bar final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false); ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon); ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue); // swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); ivEnabled = (ImageView) actionView.findViewById(R.id.ivEnabled); ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered); // Icon ivIcon.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { menu_about(); return true; } }); // Title getSupportActionBar().setTitle(null); // Netguard is busy ivQueue.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { int location[] = new int[2]; actionView.getLocationOnScreen(location); Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivQueue.getLeft(), Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop())); toast.show(); return true; } }); // On/off switch // swEnabled.setChecked(enabled); if (enabled) { ivEnabled.setImageResource(R.drawable.on); } else { ivEnabled.setImageResource(R.drawable.off); } ivEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { enabled = !enabled; boolean isChecked = enabled; Log.i(TAG, "Switch=" + isChecked); prefs.edit().putBoolean("enabled", isChecked).apply(); if (isChecked) { try { final Intent prepare = VpnService.prepare(ActivityMain.this); if (prepare == null) { Log.i(TAG, "Prepare done"); onActivityResult(REQUEST_VPN, RESULT_OK, null); } else { // Show dialog LayoutInflater inflater = LayoutInflater.from(ActivityMain.this); View view = inflater.inflate(R.layout.vpn, null, false); dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view) .setCancelable(false) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (running) { Log.i(TAG, "Start intent=" + prepare); try { // com.android.vpndialogs.ConfirmDialog required startActivityForResult(prepare, REQUEST_VPN); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, ActivityMain.this); onActivityResult(REQUEST_VPN, RESULT_CANCELED, null); prefs.edit().putBoolean("enabled", false).apply(); } } } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogVpn = null; } }).create(); dialogVpn.show(); } } catch (Throwable ex) { // Prepare failed Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); Util.sendCrashReport(ex, ActivityMain.this); prefs.edit().putBoolean("enabled", false).apply(); } } else ServiceSinkhole.stop("switch off", ActivityMain.this); } }); if (enabled) checkDoze(); // Network is metered ivMetered.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { int location[] = new int[2]; actionView.getLocationOnScreen(location); Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivMetered.getLeft(), Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop())); toast.show(); return true; } }); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); // Disabled warning // TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); // tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); final LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable); ly.setVisibility(enabled ? View.GONE : View.VISIBLE); ImageView ivClose = (ImageView) findViewById(R.id.ivClose); ivClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ly.setVisibility(View.GONE); } }); // Application list RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication); rvApplication.setHasFixedSize(true); rvApplication.setLayoutManager(new LinearLayoutManager(this)); adapter = new AdapterRule(this); rvApplication.setAdapter(adapter); rvApplication.addItemDecoration(new MyDecoration(this, MyDecoration.VERTICAL_LIST)); // Swipe to refresh TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE); swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { Rule.clearCache(ActivityMain.this); ServiceSinkhole.reload("pull", ActivityMain.this); updateApplicationList(null); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); // Listen for rule set changes IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr); // Listen for queue changes IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED); LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq); // Listen for added/removed applications IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); registerReceiver(packageChangedReceiver, intentFilter); // Fill application list updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH)); checkExtras(getIntent()); }
From source file:org.projecthdata.weight.WeightTrackerActivity.java
private boolean isConnected() { Connection<HData> connection = null; try {/* w w w . j a v a2 s . c o m*/ connection = connectionRepository.findPrimaryConnection(HData.class); } catch (IllegalArgumentException e) { String message = Log.getStackTraceString(e); Log.w(getClass().getSimpleName(), message); } return (connection != null); }
From source file:com.dm.material.dashboard.candybar.fragments.RequestFragment.java
private void getMissingApps() { mGetMissingApps = new AsyncTask<Void, Request, Boolean>() { List<Request> requests; @Override/*w w w. ja v a 2 s . c o m*/ protected void onPreExecute() { super.onPreExecute(); mProgress.setVisibility(View.VISIBLE); } @Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try { Thread.sleep(1); if (CandyBarMainActivity.sMissedApps == null) { CandyBarMainActivity.sMissedApps = RequestHelper.loadMissingApps(getActivity()); } requests = CandyBarMainActivity.sMissedApps; return true; } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; } @Override protected void onPostExecute(Boolean aBoolean) { super.onPostExecute(aBoolean); mProgress.setVisibility(View.GONE); if (aBoolean) { setHasOptionsMenu(true); mAdapter = new RequestAdapter(getActivity(), requests, mManager.getSpanCount()); mRecyclerView.setAdapter(mAdapter); Animator.showFab(mFab); } else { mRecyclerView.setAdapter(null); Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.request_appfilter_failed), Toast.LENGTH_LONG).show(); } mGetMissingApps = null; } }.execute(); }
From source file:net.olejon.mdapp.CalculatorsActivity.java
private void calculateBmi() { EditText weightEditText = (EditText) findViewById(R.id.calculators_bmi_weight); EditText heightEditText = (EditText) findViewById(R.id.calculators_bmi_height); String weightEditTextValue = weightEditText.getText().toString(); String heightEditTextValue = heightEditText.getText().toString(); if (weightEditTextValue.equals("") || heightEditTextValue.equals("")) { mTools.showToast(getString(R.string.calculators_bmi_invalid_values), 1); } else {// w ww. j ava 2 s. c om try { double weight = Double.parseDouble(weightEditTextValue); double height = Double.parseDouble(heightEditTextValue); double result = (weight) / ((height / 100) * (height / 100)); String interpretation = "<font color=\"#4caf50\">" + getString(R.string.calculators_bmi_normal_weight) + "</font>"; if (result < 18) { interpretation = "<font color=\"#ff9800\">" + getString(R.string.calculators_bmi_under_weight) + "</font>"; } else if (result >= 25 && result < 30) { interpretation = "<font color=\"#ff9800\">" + getString(R.string.calculators_bmi_over_weight) + "</font>"; } else if (result >= 30 && result < 35) { interpretation = "<font color=\"#f44336\">" + getString(R.string.calculators_bmi_obesity_1_weight) + "</font>"; } else if (result >= 35 && result < 40) { interpretation = "<font color=\"#f44336\">" + getString(R.string.calculators_bmi_obesity_2_weight) + "</font>"; } else if (result >= 40) { interpretation = "<font color=\"#f44336\">" + getString(R.string.calculators_bmi_obesity_3_weight) + "</font>"; } String bmi = String.format("%.1f", result); new MaterialDialog.Builder(mContext).title(getString(R.string.calculators_bmi_dialog_title)) .content(Html.fromHtml(getString(R.string.calculators_bmi_dialog_message_first) + "<br><b>" + bmi + "</b><br><br>" + getString(R.string.calculators_bmi_dialog_message_second) + "<br><b>" + interpretation + "</b><br><br><small><i>" + getString(R.string.calculators_bmi_dialog_message_third) + "</i></small>")) .positiveText(getString(R.string.calculators_bmi_dialog_positive_button)) .neutralText(getString(R.string.calculators_bmi_dialog_neutral_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onNeutral(MaterialDialog dialog) { showInformationDialog(); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .neutralColorRes(R.color.dark_blue).show(); } catch (Exception e) { mTools.showToast(getString(R.string.calculators_bmi_invalid_values), 1); Log.e("CalculatorsActivity", Log.getStackTraceString(e)); } } }
From source file:com.squareup.leakcanary.internal.DisplayLeakActivity.java
void updateUi() { if (leaks == null) { setTitle("Loading leaks..."); return;/*from www. jav a 2 s . c o m*/ } if (leaks.isEmpty()) { visibleLeakRefKey = null; } final AnalyzedHeap visibleLeak = getVisibleLeak(); if (visibleLeak == null) { visibleLeakRefKey = null; } ListAdapter listAdapter = listView.getAdapter(); // Reset to defaults listView.setVisibility(VISIBLE); failureView.setVisibility(GONE); if (visibleLeak != null) { AnalysisResult result = visibleLeak.result; if (result.failure != null) { listView.setVisibility(GONE); failureView.setVisibility(VISIBLE); String failureMessage = getString(R.string.leak_canary_failure_report) + LIBRARY_VERSION + " " + GIT_SHA + "\n" + Log.getStackTraceString(result.failure); failureView.setText(failureMessage); setTitle(R.string.leak_canary_analysis_failed); invalidateOptionsMenu(); setDisplayHomeAsUpEnabled(true); actionButton.setVisibility(VISIBLE); actionButton.setText(R.string.leak_canary_delete); actionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteVisibleLeak(); } }); listView.setAdapter(null); } else { final DisplayLeakAdapter adapter; if (listAdapter instanceof DisplayLeakAdapter) { adapter = (DisplayLeakAdapter) listAdapter; } else { adapter = new DisplayLeakAdapter(getResources()); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { adapter.toggleRow(position); } }); invalidateOptionsMenu(); setDisplayHomeAsUpEnabled(true); actionButton.setVisibility(VISIBLE); actionButton.setText(R.string.leak_canary_delete); actionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteVisibleLeak(); } }); } HeapDump heapDump = visibleLeak.heapDump; adapter.update(result.leakTrace, heapDump.referenceKey, heapDump.referenceName); if (result.retainedHeapSize == AnalysisResult.RETAINED_HEAP_SKIPPED) { String className = classSimpleName(result.className); setTitle(getString(R.string.leak_canary_class_has_leaked, className)); } else { String size = formatShortFileSize(this, result.retainedHeapSize); String className = classSimpleName(result.className); setTitle(getString(R.string.leak_canary_class_has_leaked_retaining, className, size)); } } } else { if (listAdapter instanceof LeakListAdapter) { ((LeakListAdapter) listAdapter).notifyDataSetChanged(); } else { LeakListAdapter adapter = new LeakListAdapter(); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { visibleLeakRefKey = leaks.get(position).heapDump.referenceKey; updateUi(); } }); invalidateOptionsMenu(); setTitle(getString(R.string.leak_canary_leak_list_title, getPackageName())); setDisplayHomeAsUpEnabled(false); actionButton.setText(R.string.leak_canary_delete_all); actionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(DisplayLeakActivity.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.leak_canary_delete_all) .setMessage(R.string.leak_canary_delete_all_leaks_title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteAllLeaks(); } }).setNegativeButton(android.R.string.cancel, null).show(); } }); } actionButton.setVisibility(leaks.size() == 0 ? GONE : VISIBLE); } }
From source file:com.dm.wallpaper.board.fragments.CategoryWallpapersFragment.java
private void filterSearch(String query) { try {/*from w w w. j a v a 2s .co m*/ mAdapter.search(query); if (mAdapter.getItemCount() == 0) { String text = String.format(getActivity().getResources().getString(R.string.search_result_empty), query); mSearchResult.setText(text); mSearchResult.setVisibility(View.VISIBLE); } else mSearchResult.setVisibility(View.GONE); } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); } }
From source file:org.brussels.gtug.attendance.AccountsActivity.java
/** * Retrieves the authorization cookie associated with the given token. This * method should only be used when running against a production appengine * backend (as opposed to a dev mode server). *///from w ww . j a va2 s .c o m private String getAuthCookie(String authToken) { DefaultHttpClient httpClient = new DefaultHttpClient(); try { // Get SACSID cookie httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); String uri = Constants.APP_SERVER_URL + "/_ah/login?continue=http://localhost/&auth=" + authToken; HttpGet method = new HttpGet(uri); HttpResponse res = httpClient.execute(method); StatusLine statusLine = res.getStatusLine(); int statusCode = statusLine.getStatusCode(); Header[] headers = res.getHeaders("Set-Cookie"); if (statusCode != 302 || headers.length == 0) { return null; } for (Cookie cookie : httpClient.getCookieStore().getCookies()) { if (AUTH_COOKIE_NAME.equals(cookie.getName())) { return AUTH_COOKIE_NAME + "=" + cookie.getValue(); } } } catch (IOException e) { Log.w(TAG, "Got IOException " + e); Log.w(TAG, Log.getStackTraceString(e)); } finally { httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); } return null; }
From source file:info.papdt.blacklight.support.Utility.java
public static void setActionBarTranslation(Activity activity, float y) { ViewGroup vg = (ViewGroup) activity.findViewById(android.R.id.content).getParent(); int count = vg.getChildCount(); if (DEBUG) {/*from w w w . j a v a2s. c o m*/ Log.d(TAG, "=========================="); } // Get the class of action bar Class<?> actionBarContainer = null; Field isSplit = null; try { actionBarContainer = Class.forName("com.android.internal.widget.ActionBarContainer"); isSplit = actionBarContainer.getDeclaredField("mIsSplit"); isSplit.setAccessible(true); } catch (Exception e) { if (DEBUG) { Log.e(TAG, Log.getStackTraceString(e)); } } for (int i = 0; i < count; i++) { View v = vg.getChildAt(i); if (v.getId() != android.R.id.content) { if (DEBUG) { Log.d(TAG, "Found View: " + v.getClass().getName()); } try { if (actionBarContainer.isInstance(v)) { if (DEBUG) { Log.d(TAG, "Found ActionBarContainer"); } if (isSplit.getBoolean(v)) { if (DEBUG) { Log.d(TAG, "Found Split Action Bar"); } continue; } } } catch (Exception e) { if (DEBUG) { Log.e(TAG, Log.getStackTraceString(e)); } } v.setTranslationY(y); } } if (DEBUG) { Log.d(TAG, "=========================="); } }
From source file:org.alfresco.mobile.android.application.manager.ActionManager.java
public static boolean actionSendMailWithAttachment(Fragment fr, String subject, String content, Uri attachment, int requestCode) { try {/*from ww w. j a v a 2 s.c om*/ Intent i = new Intent(Intent.ACTION_SEND); i.putExtra(Intent.EXTRA_SUBJECT, subject); i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(content)); i.putExtra(Intent.EXTRA_STREAM, attachment); i.setType("text/plain"); fr.startActivityForResult(Intent.createChooser(i, fr.getString(R.string.send_email)), requestCode); return true; } catch (Exception e) { MessengerManager.showToast(fr.getActivity(), R.string.decryption_failed); Log.d(TAG, Log.getStackTraceString(e)); } return false; }