Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java

private void editPasswordDialog(final String oldPass) {
    mOldPassword = oldPass;/*from   w w w . j  av a 2 s  .  c o  m*/

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText oldPassword = new AppCompatEditText(getActivity());
    if (!oldPass.isEmpty()) {
        oldPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        oldPassword.setHint(getString(R.string.old_password));
        linearLayout.addView(oldPassword);
    }

    final AppCompatEditText newPassword = new AppCompatEditText(getActivity());
    newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    newPassword.setHint(getString(R.string.new_password));
    linearLayout.addView(newPassword);

    final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity());
    confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    confirmNewPassword.setHint(getString(R.string.confirm_new_password));
    linearLayout.addView(confirmNewPassword);

    new Dialog(getActivity()).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (!oldPass.isEmpty()
                            && !oldPassword.getText().toString().equals(Utils.decodeString(oldPass))) {
                        Utils.toast(getString(R.string.old_password_wrong), getActivity());
                        return;
                    }

                    if (newPassword.getText().toString().isEmpty()) {
                        Utils.toast(getString(R.string.password_empty), getActivity());
                        return;
                    }

                    if (!newPassword.getText().toString().equals(confirmNewPassword.getText().toString())) {
                        Utils.toast(getString(R.string.password_not_match), getActivity());
                        return;
                    }

                    if (newPassword.getText().toString().length() > 32) {
                        Utils.toast(getString(R.string.password_too_long), getActivity());
                        return;
                    }

                    Prefs.saveString("password", Utils.encodeString(newPassword.getText().toString()),
                            getActivity());
                    if (mFingerprint != null) {
                        mFingerprint.setEnabled(true);
                    }
                }
            }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    mOldPassword = null;
                }
            }).show();
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override//from ww w  . j a  v  a 2 s. c  om
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}

From source file:com.emobc.android.activities.generators.FormActivityGenerator.java

/**
 * Inserts a dataItem to View depending on the particular type
 * @param activity//from   w  ww .j a v a  2 s .c  om
 * @param dataItem
 * @param formLayout
 */
private void insertField(Activity activity, FormDataItem dataItem, LinearLayout formLayout) {
    View control = null;

    switch (dataItem.getType()) {
    case INPUT_TEXT:
        control = insertTextField(activity, dataItem);
        break;
    case INPUT_NUMBER:
        control = insertNumberField(activity, dataItem);
        break;
    case INPUT_EMAIL:
        control = insertEmailField(activity, dataItem);
        break;
    case INPUT_PHONE:
        control = insertPhoneField(activity, dataItem);
        break;
    case INPUT_PASSWORD:
        control = insertPasswordField(activity, dataItem);
        break;
    case INPUT_CHECK:
        control = insertCheckField(activity, dataItem);
        break;
    case INPUT_PICKER:
        control = insertPickerField(activity, dataItem);
        break;
    default:
        break;
    }

    formLayout.addView(control);
    controlsMap.put(dataItem.getFieldName(), control);

}

From source file:com.google.samples.apps.iosched.ui.widget.CollectionView.java

private View makeNewItemRow(RowComputeResult rowInfo) {
    LinearLayout ll = new LinearLayout(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    ll.setLayoutParams(params);// w  ww . j  a  v  a  2 s  . co  m

    int nbColumns = rowInfo.group.mDisplayCols;
    if (hasCustomGroupView()) {
        nbColumns = 1;
    }
    for (int i = 0; i < nbColumns; i++) {
        View view = getItemView(rowInfo, i, null, ll);
        setupLayoutParams(view);
        ll.addView(view);
    }

    return ll;
}

From source file:jp.ne.sakura.kkkon.java.net.inetaddress.testapp.android.NetworkConnectionCheckerTestApp.java

/** Called when the activity is first created. */
@Override/*from   ww w . j ava 2s  .  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    final Context context = this.getApplicationContext();

    {
        NetworkConnectionChecker.initialize();
    }

    super.onCreate(savedInstanceState);

    /* Create a TextView and set its content.
     * the text is retrieved by calling a native
     * function.
     */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(this);
    tv.setText("reachable=");
    layout.addView(tv);
    this.textView = tv;

    Button btn1 = new Button(this);
    btn1.setText("invoke Exception");
    btn1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int count = 2;
            int[] array = new int[count];
            int value = array[count]; // invoke IndexOutOfBOundsException
        }
    });
    layout.addView(btn1);

    {
        Button btn = new Button(this);
        btn.setText("disp isReachable");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                final boolean isReachable = NetworkConnectionChecker.isReachable();
                Toast toast = Toast.makeText(context, "IsReachable=" + isReachable, Toast.LENGTH_LONG);
                toast.show();
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("upload http AsyncTask");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() {

                    @Override
                    protected Boolean doInBackground(String... paramss) {
                        Boolean result = true;
                        Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid());
                        try {
                            //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
                            Log.d(TAG, "fng=" + Build.FINGERPRINT);
                            final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
                            list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

                            HttpPost httpPost = new HttpPost(paramss[0]);
                            //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                            httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                            DefaultHttpClient httpClient = new DefaultHttpClient();
                            Log.d(TAG, "socket.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                            Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                            httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                    new Integer(5 * 1000));
                            httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                    new Integer(5 * 1000));
                            Log.d(TAG, "socket.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                            Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                    .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                            // <uses-permission android:name="android.permission.INTERNET"/>
                            // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                            HttpResponse response = httpClient.execute(httpPost);
                            Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                        } catch (Exception e) {
                            Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                            result = false;
                        }
                        Log.d(TAG, "upload finish");
                        return result;
                    }

                };

                asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug");
                asyncTask.isCancelled();
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(0.0.0.0)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        try {
                            destHost = InetAddress.getByName("0.0.0.0");
                            if (null != destHost) {
                                try {
                                    if (destHost.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + destHost.toString() + " reachable");
                                    } else {
                                        Log.d(TAG, "destHost=" + destHost.toString() + " not reachable");
                                    }
                                } catch (IOException e) {

                                }
                            }
                        } catch (UnknownHostException e) {

                        }
                        Log.d(TAG, "destHost=" + destHost);
                    }
                });
                thread.start();
                try {
                    thread.join(1000);
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }
    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(www.google.com)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        Log.d(TAG, "start");
                        try {
                            InetAddress dest = InetAddress.getByName("www.google.com");
                            if (null == dest) {
                                dest = destHost;
                            }

                            if (null != dest) {
                                final String[] uris = new String[] { "http://www.google.com/",
                                        "https://www.google.com/" };
                                for (final String destURI : uris) {
                                    URI uri = null;
                                    try {
                                        uri = new URI(destURI);
                                    } catch (URISyntaxException e) {
                                        //Log.d( TAG, e.toString() );
                                    }

                                    if (null != uri) {
                                        URL url = null;
                                        try {
                                            url = uri.toURL();
                                        } catch (MalformedURLException ex) {
                                            Log.d(TAG, "got exception:" + ex.toString(), ex);
                                        }

                                        URLConnection conn = null;
                                        if (null != url) {
                                            Log.d(TAG, "openConnection before");
                                            try {
                                                conn = url.openConnection();
                                                if (null != conn) {
                                                    conn.setConnectTimeout(3 * 1000);
                                                    conn.setReadTimeout(3 * 1000);
                                                }
                                            } catch (IOException e) {
                                                //Log.d( TAG, "got Exception" + e.toString(), e );
                                            }
                                            Log.d(TAG, "openConnection after");
                                            if (conn instanceof HttpURLConnection) {
                                                HttpURLConnection httpConn = (HttpURLConnection) conn;
                                                int responceCode = -1;
                                                try {
                                                    Log.d(TAG, "getResponceCode before");
                                                    responceCode = httpConn.getResponseCode();
                                                    Log.d(TAG, "getResponceCode after");
                                                } catch (IOException ex) {
                                                    Log.d(TAG, "got exception:" + ex.toString(), ex);
                                                }
                                                Log.d(TAG, "responceCode=" + responceCode);
                                                if (0 < responceCode) {
                                                    isReachable = true;
                                                    destHost = dest;
                                                }
                                                Log.d(TAG,
                                                        " HTTP ContentLength=" + httpConn.getContentLength());
                                                httpConn.disconnect();
                                                Log.d(TAG,
                                                        " HTTP ContentLength=" + httpConn.getContentLength());
                                            }
                                        }
                                    } // if uri

                                    if (isReachable) {
                                        //break;
                                    }
                                } // for uris
                            } else {
                            }
                        } catch (UnknownHostException e) {
                            Log.d(TAG, "dns error" + e.toString());
                            destHost = null;
                        }
                        {
                            if (null != destHost) {
                                Log.d(TAG, "destHost=" + destHost);
                            }
                        }
                        Log.d(TAG, "end");
                    }
                });
                thread.start();
                try {
                    thread.join();
                    {
                        final String addr = (null == destHost) ? ("") : (destHost.toString());
                        final String reachable = (isReachable) ? ("reachable") : ("not reachable");
                        Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable,
                                Toast.LENGTH_LONG);
                        toast.show();
                    }
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(kkkon.sakura.ne.jp)");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        Log.d(TAG, "start");
                        try {
                            InetAddress dest = InetAddress.getByName("kkkon.sakura.ne.jp");
                            if (null == dest) {
                                dest = destHost;
                            }
                            if (null != dest) {
                                try {
                                    if (dest.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + dest.toString() + " reachable");
                                        isReachable = true;
                                    } else {
                                        Log.d(TAG, "destHost=" + dest.toString() + " not reachable");
                                    }
                                    destHost = dest;
                                } catch (IOException e) {

                                }
                            } else {
                            }
                        } catch (UnknownHostException e) {
                            Log.d(TAG, "dns error" + e.toString());
                            destHost = null;
                        }
                        {
                            if (null != destHost) {
                                Log.d(TAG, "destHost=" + destHost);
                            }
                        }
                        Log.d(TAG, "end");
                    }
                });
                thread.start();
                try {
                    thread.join();
                    {
                        final String addr = (null == destHost) ? ("") : (destHost.toString());
                        final String reachable = (isReachable) ? ("reachable") : ("not reachable");
                        Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable,
                                Toast.LENGTH_LONG);
                        toast.show();
                    }
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }

    {
        Button btn = new Button(this);
        btn.setText("pre DNS query(kkkon.sakura.ne.jp) support proxy");
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                isReachable = false;
                Thread thread = new Thread(new Runnable() {

                    public void run() {
                        try {
                            String target = null;
                            {
                                ProxySelector proxySelector = ProxySelector.getDefault();
                                Log.d(TAG, "proxySelector=" + proxySelector);
                                if (null != proxySelector) {
                                    URI uri = null;
                                    try {
                                        uri = new URI("http://www.google.com/");
                                    } catch (URISyntaxException e) {
                                        Log.d(TAG, e.toString());
                                    }
                                    List<Proxy> proxies = proxySelector.select(uri);
                                    if (null != proxies) {
                                        for (final Proxy proxy : proxies) {
                                            Log.d(TAG, " proxy=" + proxy);
                                            if (null != proxy) {
                                                if (Proxy.Type.HTTP == proxy.type()) {
                                                    final SocketAddress sa = proxy.address();
                                                    if (sa instanceof InetSocketAddress) {
                                                        final InetSocketAddress isa = (InetSocketAddress) sa;
                                                        target = isa.getHostName();
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (null == target) {
                                target = "kkkon.sakura.ne.jp";
                            }
                            InetAddress dest = InetAddress.getByName(target);
                            if (null == dest) {
                                dest = destHost;
                            }
                            if (null != dest) {
                                try {
                                    if (dest.isReachable(5 * 1000)) {
                                        Log.d(TAG, "destHost=" + dest.toString() + " reachable");
                                        isReachable = true;
                                    } else {
                                        Log.d(TAG, "destHost=" + dest.toString() + " not reachable");
                                        {
                                            ProxySelector proxySelector = ProxySelector.getDefault();
                                            //Log.d( TAG, "proxySelector=" + proxySelector );
                                            if (null != proxySelector) {
                                                URI uri = null;
                                                try {
                                                    uri = new URI("http://www.google.com/");
                                                } catch (URISyntaxException e) {
                                                    //Log.d( TAG, e.toString() );
                                                }

                                                if (null != uri) {
                                                    List<Proxy> proxies = proxySelector.select(uri);
                                                    if (null != proxies) {
                                                        for (final Proxy proxy : proxies) {
                                                            //Log.d( TAG, " proxy=" + proxy );
                                                            if (null != proxy) {
                                                                if (Proxy.Type.HTTP == proxy.type()) {
                                                                    URL url = uri.toURL();
                                                                    URLConnection conn = null;
                                                                    if (null != url) {
                                                                        try {
                                                                            conn = url.openConnection(proxy);
                                                                            if (null != conn) {
                                                                                conn.setConnectTimeout(
                                                                                        3 * 1000);
                                                                                conn.setReadTimeout(3 * 1000);
                                                                            }
                                                                        } catch (IOException e) {
                                                                            Log.d(TAG, "got Exception"
                                                                                    + e.toString(), e);
                                                                        }
                                                                        if (conn instanceof HttpURLConnection) {
                                                                            HttpURLConnection httpConn = (HttpURLConnection) conn;
                                                                            if (0 < httpConn
                                                                                    .getResponseCode()) {
                                                                                isReachable = true;
                                                                            }
                                                                            Log.d(TAG, " HTTP ContentLength="
                                                                                    + httpConn
                                                                                            .getContentLength());
                                                                            Log.d(TAG, " HTTP res=" + httpConn
                                                                                    .getResponseCode());
                                                                            //httpConn.setInstanceFollowRedirects( false );
                                                                            //httpConn.setRequestMethod( "HEAD" );
                                                                            //conn.connect();
                                                                            httpConn.disconnect();
                                                                            Log.d(TAG, " HTTP ContentLength="
                                                                                    + httpConn
                                                                                            .getContentLength());
                                                                            Log.d(TAG, " HTTP res=" + httpConn
                                                                                    .getResponseCode());
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                    }
                                    destHost = dest;
                                } catch (IOException e) {
                                    Log.d(TAG, "got Excpetion " + e.toString());
                                }
                            } else {
                            }
                        } catch (UnknownHostException e) {
                            Log.d(TAG, "dns error" + e.toString());
                            destHost = null;
                        }
                        {
                            if (null != destHost) {
                                Log.d(TAG, "destHost=" + destHost);
                            }
                        }
                    }
                });
                thread.start();
                try {
                    thread.join();
                    {
                        final String addr = (null == destHost) ? ("") : (destHost.toString());
                        final String reachable = (isReachable) ? ("reachable") : ("not reachable");
                        Toast toast = Toast.makeText(context, "DNS result=\n" + addr + "\n " + reachable,
                                Toast.LENGTH_LONG);
                        toast.show();
                    }
                } catch (InterruptedException e) {

                }
            }
        });
        layout.addView(btn);
    }

    setContentView(layout);
}

From source file:edu.rowan.app.fragments.FoodRatingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout view = new LinearLayout(getActivity());
    view.setOrientation(LinearLayout.VERTICAL);
    // view pager indicator
    TitlePageIndicator pageIndicator = new TitlePageIndicator(getActivity());
    pageIndicator.setBackgroundResource(R.color.rowanBrown);
    fragmentPager = new ViewPager(getActivity());
    fragmentPager.setId(VIEW_PAGER_ID);/*from w w  w.  jav  a  2s  . co  m*/
    fragmentAdapter = new FoodRatingAdapter(getChildFragmentManager());
    fragmentPager.setAdapter(fragmentAdapter);
    //View view = inflater.inflate(R.layout.activity_main, container, false);

    pageIndicator.setViewPager(fragmentPager);
    view.addView(pageIndicator);
    view.addView(fragmentPager);
    return view;
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

public View addCloseButtonToClosableDialogView(View dialogView, final AlertDialog dialogToCloseOnclick) {
    MBStyleHandler styleHandler = MBViewBuilderFactory.getInstance().getStyleHandler();

    FragmentActivity context = getActivity();
    LinearLayout wrapper = new LinearLayout(context);
    wrapper.setOrientation(LinearLayout.VERTICAL);

    styleHandler.styleDialogCloseButtonWrapper(wrapper);

    LayoutParams prevDialogViewParams = dialogView.getLayoutParams();
    int width = LayoutParams.MATCH_PARENT;
    int height = LayoutParams.MATCH_PARENT;

    if (prevDialogViewParams != null) {
        width = prevDialogViewParams.width;
        height = prevDialogViewParams.height;
    }/*from ww  w  .  j a  v a 2  s  . c om*/

    LinearLayout.LayoutParams dialogViewParams = new LinearLayout.LayoutParams(width, height);
    dialogView.setLayoutParams(dialogViewParams);
    wrapper.addView(dialogView);

    LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    Button closeButton = new Button(context);
    closeButton.setLayoutParams(buttonParams);
    closeButton.setText(MBLocalizationService.getInstance().getTextForKey("Close"));
    styleHandler.styleDialogCloseButton(closeButton);
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MBViewManager.getInstance().endDialog(getDialogController().getName(), false);
        }
    });

    wrapper.addView(closeButton);

    return wrapper;
}

From source file:com.gh4a.activities.IssueCreateActivity.java

public void fillLabels(List<Label> labels) {
    Gh4Application app = Gh4Application.get(this);
    LinearLayout labelLayout = (LinearLayout) findViewById(R.id.ll_labels);

    for (final Label label : labels) {
        final View rowView = getLayoutInflater().inflate(R.layout.row_issue_create_label, null);
        View viewColor = rowView.findViewById(R.id.view_color);
        viewColor.setBackgroundColor(Color.parseColor("#" + label.getColor()));

        final TextView tvLabel = (TextView) rowView.findViewById(R.id.tv_title);
        tvLabel.setTypeface(app.condensed);
        tvLabel.setText(label.getName());
        tvLabel.setOnClickListener(this);
        tvLabel.setTag(label);//from  w  ww  . j  av  a  2s.  co  m

        if (isInEditMode()) {
            handleLabelClick(tvLabel, label, mSelectedLabels.contains(label));
        }

        labelLayout.addView(rowView);
    }
}

From source file:com.guipenedo.pokeradar.activities.MapsActivity.java

/**
 * Manipulates the map once available.//w  w  w.j  ava 2s  . c  om
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.setOnMapLongClickListener(this);
    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            onConnected(null);
            update();
            return true;
        }
    });
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker m) {
            PMarker marker = pokemonMarkers.get(m.getId());
            if (marker == null || marker.type != PMarker.MarkerType.GYM)
                return;
            Intent gymIntent = new Intent(MapsActivity.this, GymDetailsActivity.class);
            gymIntent.putExtra("gymDetails", (PGym) marker);
            startActivity(gymIntent);
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        @Override
        public View getInfoContents(final Marker m) {

            Context mContext = MapsActivity.this;

            LinearLayout info = new LinearLayout(mContext);
            info.setOrientation(LinearLayout.VERTICAL);

            TextView title = new TextView(mContext);
            title.setText(m.getTitle());
            title.setTypeface(null, Typeface.BOLD);
            title.setGravity(Gravity.CENTER);
            info.addView(title);

            final PMarker marker = pokemonMarkers.get(m.getId());
            long timestamp = -1;
            if (marker != null) {
                if (marker.type == PMarker.MarkerType.CENTER) {
                    TextView littleNotice = new TextView(mContext);
                    littleNotice.setText(R.string.scan_center_infowindow);
                    littleNotice.setGravity(Gravity.CENTER);
                    info.addView(littleNotice);
                } else if (marker.type == PMarker.MarkerType.LUREDPOKESTOP) {
                    PPokestop pokestopMarker = (PPokestop) marker;
                    timestamp = pokestopMarker.getTimestamp();
                    TextView remainingTime = new TextView(mContext);
                    String text = String.format(getString(R.string.lured_remaining), Utils.countdownFromMillis(
                            mContext, pokestopMarker.getTimestamp() - System.currentTimeMillis()));
                    remainingTime.setText(text);
                    remainingTime.setGravity(Gravity.CENTER);
                    info.addView(remainingTime);
                    TextView expireTime = new TextView(mContext);
                    expireTime.setText(Utils.timeFromMillis(pokestopMarker.getTimestamp()));
                    expireTime.setGravity(Gravity.CENTER);
                    info.addView(expireTime);
                } else if (marker.type == PMarker.MarkerType.GYM) {
                    PGym gymMarker = (PGym) marker;
                    Team team = Team.fromTeamColor(gymMarker.getTeam());
                    TextView teamName = new TextView(mContext);
                    teamName.setText(team.getName());
                    teamName.setTextColor(team.getColor());
                    teamName.setGravity(Gravity.CENTER);
                    info.addView(teamName);
                    TextView prestige = new TextView(mContext);
                    prestige.setText(String.format(getString(R.string.gym_points), gymMarker.getPoints()));
                    prestige.setGravity(Gravity.CENTER);
                    info.addView(prestige);
                    TextView clickDetails = new TextView(mContext);
                    clickDetails.setText(R.string.gym_details);
                    clickDetails.setTypeface(null, Typeface.BOLD);
                    clickDetails.setGravity(Gravity.CENTER);
                    info.addView(clickDetails);
                } else if (marker.type == PMarker.MarkerType.POKEMON) {
                    PPokemon pokemonMarker = (PPokemon) marker;
                    timestamp = pokemonMarker.getTimestamp();
                    final TextView remainingTime = new TextView(mContext);
                    remainingTime.setText(
                            String.format(getString(R.string.pokemon_despawns_time), Utils.countdownFromMillis(
                                    mContext, pokemonMarker.getTimestamp() - System.currentTimeMillis())));
                    remainingTime.setGravity(Gravity.CENTER);
                    info.addView(remainingTime);
                    TextView expireTime = new TextView(mContext);
                    expireTime.setText(Utils.timeFromMillis(pokemonMarker.getTimestamp()));
                    expireTime.setGravity(Gravity.CENTER);
                    info.addView(expireTime);
                }
                if (timestamp != -1 && (countdownMarker == null || !countdownMarker.equals(m.getId()))) {
                    countdownMarker = m.getId();
                    new CountDownTimer(timestamp - System.currentTimeMillis(), 1000) {

                        public void onTick(long millisUntilFinished) {
                            if (markers.contains(m) && m.isInfoWindowShown())
                                m.showInfoWindow();
                            else
                                cancel();
                        }

                        @Override
                        public void onFinish() {
                            countdownMarker = null;
                        }
                    }.start();
                }
            }
            return info;
        }
    });
    update();
}

From source file:cn.count.easydrive366.CarRegistrationActivity.java

@Override
protected void initView() {
    try {/*w  w w  .ja va2 s .co m*/
        //check_date
        //((TextView)findViewById(R.id.txt_carregistration_brand)).setText(_result.getString("brand"));
        ((TextView) findViewById(R.id.txt_carregistration_check_date)).setText(_result.getString("check_date"));
        ((TextView) findViewById(R.id.txt_carregistration_car_typename))
                .setText(_result.getString("car_typename"));
        ((TextView) findViewById(R.id.txt_carregistration_engine_no)).setText(_result.getString("engine_no"));
        //((TextView)findViewById(R.id.txt_carregistration_issue_date  )).setText(_result.getString("issue_date"));
        ((TextView) findViewById(R.id.txt_carregistration_model)).setText(_result.getString("model"));
        ((TextView) findViewById(R.id.txt_carregistration_plate_no)).setText(_result.getString("plate_no"));
        ((TextView) findViewById(R.id.txt_carregistration_registration_date))
                .setText(_result.getString("registration_date"));
        ((TextView) findViewById(R.id.txt_carregistration_untreated_fine))
                .setText(_result.getString("untreated_fine"));
        ((TextView) findViewById(R.id.txt_carregistration_untreated_mark))
                .setText(_result.getString("untreated_mark"));
        ((TextView) findViewById(R.id.txt_carregistration_untreated_number))
                .setText(_result.getString("untreated_number"));
        ((TextView) findViewById(R.id.txt_carregistration_vin)).setText(_result.getString("vin"));
        ((TextView) findViewById(R.id.txt_carregistration_owner_name)).setText(_result.getString("owner_name"));
        ((TextView) findViewById(R.id.txt_carregistration_owner_license))
                .setText(_result.getString("owner_license"));
        this.setupRightButton();
        /*
        ((Button)findViewById(R.id.btn_carregistration_edit)).setOnClickListener(new OnClickListener(){
                
           @Override
           public void onClick(View v) {
              Intent intent = new Intent(CarRegistrationActivity.this,CarRegistrationEditActivity.class);
              intent.putExtra("data", _result.toString());
              startActivityForResult(intent,0);
                      
           }});
           */
        ((Button) findViewById(R.id.btn_carregistration_search)).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CarRegistrationActivity.this, ViolationSearchActivity.class);
                //intent.putExtra("data", _result.toString());
                startActivityForResult(intent, 1);

            }
        });
        LinearLayout items = (LinearLayout) findViewById(R.id.layout_shops);
        items.removeAllViews();
        for (int i = 0; i < _shops.length(); i++) {
            JSONObject obj = _shops.getJSONObject(i);
            CarShopItem item = new CarShopItem(this, null, obj.getString("name"),
                    String.format("%s(%s)", obj.getString("address"), obj.get("phone")));
            item.setTag(obj.getString("url"));
            item.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    String url = (String) v.getTag();
                    if (url != null && !url.isEmpty()) {
                        Intent intent = new Intent(CarRegistrationActivity.this, BrowserActivity.class);
                        intent.putExtra("url", url);
                        CarRegistrationActivity.this.startActivity(intent);

                    }

                }
            });
            items.addView(item);
        }
        this.endRefresh();
    } catch (Exception e) {
        log(e);
    }

}