Example usage for android.widget LinearLayout VERTICAL

List of usage examples for android.widget LinearLayout VERTICAL

Introduction

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

Prototype

int VERTICAL

To view the source code for android.widget LinearLayout VERTICAL.

Click Source Link

Usage

From source file:com.ylq.commonui.AbSlidingTabView.java

/**
 * Instantiates a new ab sliding tab view.
 *
 * @param context the context//from  w w w .  ja  v  a2 s.  com
 * @param attrs the attrs
 */
public AbSlidingTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        Log.e(TAG, "AbSlidingTabView?context,FragmentActivity");
    }

}

From source file:com.example.appf.CS3570.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();/*from ww w.j  a  va 2s.c  o m*/
    Bundle extras = intent.getExtras();
    cam = false;

    // Just in case we are coming from the ServerActivity
    if (extras != null) {
        if (extras.containsKey("server_name"))
            SERVER_IP = extras.getString("server_name");
        if (extras.containsKey("server_port"))
            SERVERPORT = Integer.parseInt(extras.getString("server_port"));
    }
    filter = new IMUfilter(.1f, 5);
    filter.reset();

    // Set up reset button
    Button b = new Button(this);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            filter.reset();
        }
    });
    b.setText("Reset");

    // Set up camera mode. Are we going to use this?
    Button c = new Button(this);
    c.setText("Camera Mode");
    c.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            filter.reset();
            mGLView.mRenderer.mCamera = new Camera();
            cam = !cam;
        }
    });
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setBackgroundColor(Color.parseColor("#21C9FF"));
    ll.addView(b);
    ll.addView(c);
    // Create a GLSurfaceView instance and set it
    // as the ContentView for this Activity
    mGLView = new MyGLSurfaceView(this, this);
    ll.addView(mGLView);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    gyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    setContentView(ll);
    new Thread(new SocketThread()).start();
}

From source file:com.dreamchen.useful.mouserace.view.sliding.AbSlidingSmoothTabView.java

/**
 * Instantiates a new ab sliding smooth tab view.
 *
 * @param context the context/*from  ww  w.  j a  v  a 2  s  .  co m*/
 * @param attrs the attrs
 */
public AbSlidingSmoothTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new AbHorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);
    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabScrollView, layoutParamsFW);

    //?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingSmoothTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getSupportFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabScrollView.setOnScrollListener(new AbHorizontalScrollView.AbOnScrollListener() {

        @Override
        public void onScrollToRight() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollToRight");
        }

        @Override
        public void onScrollToLeft() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollToLeft");
        }

        @Override
        public void onScrollStoped() {
            AbLogUtil.d(AbSlidingSmoothTabView.class, "onScrollStoped");
        }

        @Override
        public void onScroll(int arg1) {
            scrollX = arg1;
            View view = mTabLayout.getChildAt(mSelectedTabIndex);
            int toX = view.getLeft() - scrollX;

            AbLogUtil.d(AbSlidingSmoothTabView.class, "X" + startX + "to" + toX);
            imageSlide(mTabImg, startX, toX, 0, 0);
            startX = toX;
        }
    });
}

From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Feature feature = featuresList.get(position);

    int bgColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formbgcolor);
    int textColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formcolor);

    ScrollView scrollView = new ScrollView(context);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);/*from   w  ww .  ja v a 2s  .com*/
    scrollLayoutParams.setMargins(10, 10, 10, 10);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setBackgroundColor(bgColor);

    LinearLayout linearLayoutView = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    int margin = 10;
    layoutParams.setMargins(margin, margin, margin, margin);
    linearLayoutView.setLayoutParams(layoutParams);
    linearLayoutView.setOrientation(LinearLayout.VERTICAL);
    int padding = 10;
    linearLayoutView.setPadding(padding, padding, padding, padding);
    scrollView.addView(linearLayoutView);

    List<String> attributeNames = feature.getAttributeNames();
    List<String> attributeValues = feature.getAttributeValuesStrings();
    List<String> attributeTypes = feature.getAttributeTypes();
    for (int i = 0; i < attributeNames.size(); i++) {
        final String name = attributeNames.get(i);
        String value = attributeValues.get(i);
        String typeString = attributeTypes.get(i);
        EDataType type = EDataType.getType4Name(typeString);

        TextView textView = new TextView(context);
        textView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(padding, padding, padding, padding);
        textView.setText(name);
        textView.setTextColor(textColor);
        // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        linearLayoutView.addView(textView);

        final TextView editView = getEditView(feature, name, type, value);
        LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        editViewParams.setMargins(margin, 0, margin, 0);
        editView.setLayoutParams(editViewParams);
        editView.setPadding(padding * 2, padding, padding * 2, padding);
        editView.setFocusable(!isReadOnly);

        if (isReadOnly) {
            editView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    String text = editView.getText().toString();
                    FeatureUtilities.viewIfApplicable(v.getContext(), text);
                    return false;
                }
            });
        }
        linearLayoutView.addView(editView);
    }

    /*
     * add also area and length
     */
    if (feature.getOriginalArea() > -1) {
        TextView areaTextView = new TextView(context);
        areaTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        areaTextView.setPadding(padding, padding, padding, padding);
        areaTextView.setText(context.getString(eu.geopaparazzi.core.R.string.area_colon)
                + areaLengthFormatter.format(feature.getOriginalArea()));
        areaTextView.setTextColor(textColor);
        TextView lengthTextView = new TextView(context);
        lengthTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        lengthTextView.setPadding(padding, padding, padding, padding);
        lengthTextView.setText(context.getString(eu.geopaparazzi.core.R.string.length_colon)
                + areaLengthFormatter.format(feature.getOriginalLength()));
        lengthTextView.setTextColor(textColor);
        linearLayoutView.addView(areaTextView);
        linearLayoutView.addView(lengthTextView);
    }
    container.addView(scrollView);

    return scrollView;
}

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 a v  a 2  s . 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:com.gitstudy.rili.liarbry.CalendarLayout.java

public CalendarLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(LinearLayout.VERTICAL);
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CalendarLayout);
    mContentViewId = array.getResourceId(R.styleable.CalendarLayout_calendar_content_view_id, 0);
    mDefaultStatus = array.getInt(R.styleable.CalendarLayout_default_status, STATUS_EXPAND);
    mCalendarShowMode = array.getInt(R.styleable.CalendarLayout_calendar_show_mode,
            CALENDAR_SHOW_MODE_BOTH_MONTH_WEEK_VIEW);
    mGestureMode = array.getInt(R.styleable.CalendarLayout_gesture_mode, GESTURE_MODE_DEFAULT);
    array.recycle();//from   w ww.  ja v a2  s  .  c  o  m
    mVelocityTracker = VelocityTracker.obtain();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.chrslee.csgopedia.app.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);//from   w  ww.jav  a 2  s. c om
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:com.thelastcrusade.soundstream.components.ConnectFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_connect, container, false);

    ((CoreActivity) getActivity()).hidePlaybar();

    int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
    if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
        ((LinearLayout) v).setOrientation(LinearLayout.HORIZONTAL);
        LinearLayout.LayoutParams clickableParams = new LinearLayout.LayoutParams(0,
                LinearLayout.LayoutParams.MATCH_PARENT, 1);
        clickableParams.setMargins(5, 10, 10, 10);
        v.findViewById(R.id.join).setLayoutParams(clickableParams);
        clickableParams.setMargins(10, 10, 5, 10);
        v.findViewById(R.id.create).setLayoutParams(clickableParams);
    } else {/*from ww w . j a v  a 2  s  .  c o  m*/
        ((LinearLayout) v).setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams clickableParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1);
        clickableParams.setMargins(10, 5, 10, 10);
        v.findViewById(R.id.join).setLayoutParams(clickableParams);
        clickableParams.setMargins(10, 10, 10, 5);
        v.findViewById(R.id.create).setLayoutParams(clickableParams);
    }
    View create = v.findViewById(R.id.create);
    create.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Transitions.transitionToHome((CoreActivity) getActivity());
            ((CoreActivity) getActivity()).enableSlidingMenu();
            //add the playbar fragment onto the active content view
            ((CoreActivity) getActivity()).showPlaybar();
        }
    });
    create.setContentDescription(ContentDescriptionUtils.CREATE);

    this.joinView = v.findViewById(R.id.join);
    this.joinView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new WithBluetoothEnabled(getActivity(), getConnectionService()).run(new Runnable() {

                @Override
                public void run() {
                    getConnectionService().broadcastSelfAsGuest(getActivity());
                }
            });
        }
    });
    joinView.setContentDescription(ContentDescriptionUtils.CONNECT);

    TextView joinText = (TextView) v.findViewById(R.id.join_network_id);
    joinText.setText(String.format(getString(R.string.join_network), BluetoothUtils.getLocalBluetoothName()));

    if (savedInstanceState != null) {
        isSearching = savedInstanceState.getBoolean(SEARCHING_TAG);
        if (isSearching)
            setJoinToSearchingState();
    }
    return v;
}

From source file:com.euphor.paperpad.widgets.GridFragment.java

/**
 * Provide default implementation to return a simple grid view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a GridView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the grid is empty.
 * //ww w . ja va 2s  .c  o  m
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    GridView lv = new GridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:edu.byu.scriptures.controller.fragment.RestartableRecyclerFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *///from  www  .j a v  a2s  . c o  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(18);

    int padding = ((MainActivity) getActivity()).getMetricsManager().dpToRawPixels(20);

    tv.setPadding(padding, 0, padding, 0);
    tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_normal));
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    RecyclerView recyclerView = new RecyclerView(getActivity());
    recyclerView.setId(android.R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    //        lv.setDrawSelectorOnTop(false);
    lframe.addView(recyclerView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}