List of usage examples for android.view LayoutInflater from
public static LayoutInflater from(Context context)
From source file:abanoubm.dayra.main.Main.java
@Override protected void onCreate(Bundle savedInstanceState) { if (Utility.getArabicLang(getApplicationContext()) == 1) { Utility.setArabicLang(getApplicationContext(), 2); Locale myLocale = new Locale("ar"); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;/*from ww w .j av a 2 s.c o m*/ res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } super.onCreate(savedInstanceState); setContentView(R.layout.act_main); ((TextView) findViewById(R.id.subhead1)).setText(R.string.app_name); ((TextView) findViewById(R.id.subhead2)).setText(BuildConfig.VERSION_NAME); findViewById(R.id.nav_back).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); ((TextView) findViewById(R.id.footer)).setText("dayra " + BuildConfig.VERSION_NAME + " @" + new SimpleDateFormat("yyyy", Locale.getDefault()).format(new Date()) + " Abanoub M."); if (!Utility.getDayraName(getApplicationContext()).equals("")) { startActivity(new Intent(getApplicationContext(), Home.class)); finish(); } ListView lv = (ListView) findViewById(R.id.home_list); mMenuItemAdapter = new MenuItemAdapter(getApplicationContext(), new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.sign_menu))), 1); lv.setAdapter(mMenuItemAdapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: sign(); break; case 1: register(); break; case 2: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { importDB(); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, IMPORT_REQUEST); } break; case 3: startActivity(new Intent(Intent.ACTION_VIEW).setData( Uri.parse("https://drive.google.com/file/d/0B1rNCm5K9cvwVXJTTzNqSFdrVk0/view"))); break; case 4: startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( "https://drive.google.com/open?id=1flSRdoiIT_hNd96Kxz3Ww3EhXDLZ45FhwFJ2hF9vl7g"))); break; case 5: { AlertDialog.Builder builder = new AlertDialog.Builder(Main.this); builder.setTitle(R.string.label_choose_language); builder.setItems(getResources().getStringArray(R.array.language_menu), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String temp; if (which == 1) { temp = "en"; Utility.setArabicLang(getApplicationContext(), 0); } else { temp = "ar"; Utility.setArabicLang(getApplicationContext(), 2); } Locale myLocale = new Locale(temp); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); finish(); startActivity(new Intent(getIntent())); } }); builder.create().show(); } break; case 6: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/453595434816965")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/dayraapp")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 7: try { getPackageManager().getPackageInfo("com.facebook.katana", 0); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1363784786")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (Exception e) { startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/EngineeroBono")) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } break; case 8: Uri uri = Uri.parse("market://details?id=" + getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); try { startActivity(goToMarket); } catch (Exception e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); } break; case 9: if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*"); startActivity( intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)); } else { ActivityCompat.requestPermissions(Main.this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, FOLDER_REQUEST); } break; case 10: LayoutInflater li = LayoutInflater.from(getApplicationContext()); final View aboutView = li.inflate(R.layout.dialogue_about, null, false); final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create(); ad.setView(aboutView, 0, 0, 0, 0); ad.show(); ((TextView) aboutView.findViewById(R.id.about)) .setText(String.format(getResources().getString(R.string.copyright), Calendar.getInstance().get(Calendar.YEAR))); ((TextView) aboutView.findViewById(R.id.notice)).setText(GoogleApiAvailability.getInstance() .getOpenSourceSoftwareLicenseInfo(getApplicationContext())); aboutView.findViewById(R.id.btn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ad.cancel(); } }); break; } } }); }
From source file:android.support.v17.leanback.widget.AbstractMediaItemPresenter.java
@Override protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) { Context context = parent.getContext(); if (mThemeId != 0) { context = new ContextThemeWrapper(context, mThemeId); }/*from ww w. j a v a 2 s . c om*/ View view = LayoutInflater.from(context).inflate(R.layout.lb_row_media_item, parent, false); final ViewHolder vh = new ViewHolder(view); vh.mRowPresenter = this; if (mBackgroundColorSet) { vh.mMediaRowView.setBackgroundColor(mBackgroundColor); } return vh; }
From source file:br.com.oficinatablet.chats.fragments.ChatSectionFragment.java
private void loadDialog() { View viewInflated = LayoutInflater.from(getContext()).inflate(R.layout.dialog_with_edit_text, (ViewGroup) getView(), false); // Set up do textInput final TextInputLayout textInput = (TextInputLayout) viewInflated.findViewById(R.id.dialog_input); final AlertDialog builder = new AlertDialog.Builder(getActivity(), R.style.CustomDialog) //adciona Titulo .setTitle("Criar Grupo") //adciona view customizada ao dialog .setView(viewInflated)/*from w w w . ja v a 2 s. co m*/ //add botoes .setPositiveButton(R.string.create, null).setNegativeButton(R.string.cancel, null).create(); // aes customizadas para os botes builder.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button positive = builder.getButton(AlertDialog.BUTTON_POSITIVE); positive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String chatGroupName = textInput.getEditText().getText().toString(); if (TextUtils.isEmpty(chatGroupName)) { textInput.setErrorEnabled(true); textInput.setError("Nome Obrigatorio"); return; } textInput.setErrorEnabled(false); textInput.setError(""); createGroupChat(chatGroupName, builder); } }); Button negative = builder.getButton(AlertDialog.BUTTON_NEGATIVE); negative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { builder.cancel(); } }); } }); /* Show the dialog */ builder.show(); }
From source file:com.njlabs.amrita.aid.landing.Landing.java
public void checkForUpdates() { OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).followSslRedirects(true).build(); Request.Builder request = new Request.Builder().url("https://api.codezero.xyz/aid/latest"); client.newCall(request.build()).enqueue(new Callback() { @Override// ww w.j a va2 s.c o m public void onFailure(Call call, IOException e) { Ln.e(e); } @Override public void onResponse(Call call, final Response rawResponse) throws IOException { final String responseString = rawResponse.body().string(); ((Activity) baseContext).runOnUiThread(new Runnable() { @Override public void run() { JSONObject response; try { response = new JSONObject(responseString); String status = ""; status = response.getString("status"); if (status.equals("ok")) { Double Latest = 0.0; String Description = null; try { Latest = response.getDouble("version"); Description = response.getString("description"); } catch (JSONException e) { FirebaseCrash.report(e); } if (Latest > BuildConfig.VERSION_CODE) { AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(Landing.this); LayoutInflater factory = LayoutInflater.from(Landing.this); final View changelogView = factory.inflate(R.layout.webview_dialog, null); LinearLayout WebViewDialogLayout = (LinearLayout) changelogView .findViewById(R.id.WebViewDialogLayout); WebViewDialogLayout.setPadding(5, 5, 5, 5); WebView changelogWebView = (WebView) changelogView .findViewById(R.id.LicensesView); changelogWebView.loadData(String.format("%s", Description), "text/html", "utf-8"); changelogWebView.setPadding(5, 5, 5, 5); changelogWebView.setBackgroundColor(0); changelogWebView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); changelogWebView.setLongClickable(false); updateDialogBuilder.setView(changelogView).setCancelable(true) .setCancelable(false) .setNegativeButton("Dismiss", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .setPositiveButton("Update Now", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri .parse("market://details?id=com.njlabs.amrita.aid"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); } }); AlertDialog alert = updateDialogBuilder.create(); alert.setTitle("Update Available"); alert.setIcon(R.mipmap.ic_launcher); alert.show(); } } } catch (Exception e) { Ln.e(e); } } }); } }); }
From source file:android.support.v7.app.WindowDecorActionBar.java
@Override public void setCustomView(int resId) { setCustomView(LayoutInflater.from(getThemedContext()).inflate(resId, mDecorToolbar.getViewGroup(), false)); }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
/** * Create a new BrowserBookmarksPage.//from w ww. jav a2s . c o m */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); /* SharedPreferences prefs = BrowserSettings.getInstance().getPreferences(); try { mState = new JSONObject(prefs.getString(PREF_GROUP_STATE, "{}")); } catch (JSONException e) { // Parse failed, clear preference and start with empty state prefs.edit().remove(PREF_GROUP_STATE).apply(); } */ mState = new JSONObject(); // Bundle args = getArguments(); mDisableNewWindow = icicle == null ? false : icicle.getBoolean(EXTRA_DISABLE_WINDOW, false); /* // setHasOptionsMenu(true); if (mCallbacks == null && this instanceof CombinedBookmarksCallbacks) { mCallbacks = new CombinedBookmarksCallbackWrapper( (CombinedBookmarksCallbacks) this); }*/ mRoot = LayoutInflater.from(this).inflate(R.layout.combo_bookmarks, null, false); mEmptyView = mRoot.findViewById(android.R.id.empty); mGrid = (BookmarkExpandableView) mRoot.findViewById(R.id.grid); mGrid.setOnChildClickListener(this); mGrid.setColumnWidthFromLayout(R.layout.combo_bookmark_thumbnail); mGrid.setBreadcrumbController(this); setEnableContextMenu(mEnableContextMenu); // Start the loaders LoaderManager lm = getLoaderManager(); lm.restartLoader(LOADER_ACCOUNTS, null, this); this.setContentView(mRoot); }
From source file:com.abc.driver.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_weixin); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mTabPager = (ViewPager) findViewById(R.id.tabpager); mTabPager.setOnPageChangeListener(new MyOnPageChangeListener()); mTab1 = (ImageView) findViewById(R.id.img_weixin); mTab2 = (ImageView) findViewById(R.id.img_address); mTab3 = (ImageView) findViewById(R.id.img_friends); mTab4 = (ImageView) findViewById(R.id.img_settings); mTabImg = (ImageView) findViewById(R.id.img_tab_now); mTab1.setOnClickListener(new MyOnClickListener(0)); mTab2.setOnClickListener(new MyOnClickListener(1)); mTab3.setOnClickListener(new MyOnClickListener(2)); mTab4.setOnClickListener(new MyOnClickListener(3)); Display currDisplay = getWindowManager().getDefaultDisplay(); int displayWidth = currDisplay.getWidth(); int displayHeight = currDisplay.getHeight(); one = displayWidth / 4;/*from w w w. j a va2 s . co m*/ two = one * 2; three = one * 3; LayoutInflater mLi = LayoutInflater.from(this); // View view1 = mLi.inflate(R.layout.main_tab_horder_create, null); View view1 = mLi.inflate(R.layout.main_tab_truckplan, null); View view2 = mLi.inflate(R.layout.main_tab_huoyun, null); View view3 = mLi.inflate(R.layout.main_tab_horder, null); View view4 = mLi.inflate(R.layout.main_tab_me, null); final ArrayList<View> views = new ArrayList<View>(); views.add(view1); views.add(view2); views.add(view3); views.add(view4); PagerAdapter mPagerAdapter = new PagerAdapter() { @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public int getCount() { return views.size(); } @Override public void destroyItem(View container, int position, Object object) { ((ViewPager) container).removeView(views.get(position)); } @Override public Object instantiateItem(View container, int position) { ((ViewPager) container).addView(views.get(position)); return views.get(position); } }; mTabPager.setAdapter(mPagerAdapter); initData(); }
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private View createTabView(Context context, String text, int imageResource) { View view = LayoutInflater.from(context).inflate(R.layout.activity_home_tab_view, null); ImageView bg;/* www .j a v a 2 s . c o m*/ if (imageResource == -1) { bg = (ImageView) view.findViewById(R.id.tab_widget_icon); if (mSession.getUpgradeNumber() > 0) { drawUpdateCount(this, getResources(), bg, true); } else { bg.setImageResource(R.drawable.main_tab_app_manager_selector); } } else { bg = (ImageView) view.findViewById(R.id.tab_widget_icon); bg.setImageResource(imageResource); } TextView textview = (TextView) view.findViewById(R.id.tab_widget_content); textview.setText(text); return view; }
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
@SuppressLint("NewApi") private View createUpdatesFoundDialogContentsView(Update update) { Context context = activity;/*from www.j a va2 s.c o m*/ final AlertDialog.Builder builder; // Workaround for dialog theme problems if (android.os.Build.VERSION.SDK_INT > 10) { builder = new AlertDialog.Builder(context); context = builder.getContext(); } else { context = new ContextThemeWrapper(context, android.R.style.Theme_Dialog); builder = new AlertDialog.Builder(context); } builder.setTitle("Send feedback"); final LayoutInflater inflater = LayoutInflater.from(context); final View dialogContentsView = inflater.inflate(R.layout.updater_dialog_update_found, null, false); final TextView messageTextView = (TextView) dialogContentsView .findViewById(R.id.dialog_update_found_message); final TextView warningTextView = (TextView) dialogContentsView .findViewById(R.id.dialog_update_found_warning); final TextView whatIsNewTextView = (TextView) dialogContentsView .findViewById(R.id.dialog_update_found_what_is_new); String warnings = null; String message = null; String whatIsNew = null; if (update.description != null) { warnings = update.description.get(UpdateDescription.KEY_WARNINGS); message = update.description.get(UpdateDescription.KEY_MESSAGE); whatIsNew = update.description.get(UpdateDescription.KEY_WHAT_IS_NEW); } if (Utilities.isNullOrEmpty(message)) { messageTextView.setVisibility(View.GONE); } else { messageTextView.setText(message); } if (Utilities.isNullOrEmpty(warnings)) { warningTextView.setVisibility(View.GONE); } else { warningTextView.setText(warnings); } if (Utilities.isNullOrEmpty(whatIsNew)) { whatIsNewTextView.setVisibility(View.GONE); } else { whatIsNewTextView.setText(whatIsNew); } return dialogContentsView; }
From source file:se.anyro.nfc_reader.TagViewer.java
void buildTagViews(NdefMessage[] msgs) { if (msgs == null || msgs.length == 0) { return;/* w ww . jav a2 s . c o m*/ } LayoutInflater inflater = LayoutInflater.from(this); LinearLayout content = mTagContent; // Parse the first message in the list // Build views for all of the sub records Date now = new Date(); List<ParsedNdefRecord> records = NdefMessageParser.parse(msgs[0]); final int size = records.size(); for (int i = 0; i < size; i++) { TextView timeView = new TextView(this); timeView.setText(TIME_FORMAT.format(now)); content.addView(timeView, 0); ParsedNdefRecord record = records.get(i); content.addView(record.getView(this, inflater, content, i), 1 + i); content.addView(inflater.inflate(R.layout.tag_divider, content, false), 2 + i); } }