ro.adriancoman.app.TermsActivity.java Source code

Java tutorial

Introduction

Here is the source code for ro.adriancoman.app.TermsActivity.java

Source

package ro.adriancoman.app;

import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.net.Uri;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import ro.adriancoman.app.helpers.DrawerItemClickListener;

public class TermsActivity extends ActionBarActivity {

    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_terms);
        context = getBaseContext();

        createDrawer(savedInstanceState);

        setUpUi();
        TextView am_tv_linkDia = (TextView) findViewById(R.id.am_tv_linkDia);
        am_tv_linkDia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uriUrl = Uri.parse("http://diacritica.wordpress.com/");
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);
            }
        });
        TextView am_tv_linkSti = (TextView) findViewById(R.id.am_tv_linkSc);
        am_tv_linkSti.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uriUrl = Uri.parse("http://scri.ro/");
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);
            }
        });
        TextView am_tv_terms = (TextView) findViewById(R.id.am_tv_terms);
        am_tv_terms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uriUrl = Uri.parse("http://www.adriancoman.ro/stii-sa-scrii-termeni/");
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);
            }
        });
        TextView am_tv_about = (TextView) findViewById(R.id.am_tv_about);
        am_tv_about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uriUrl = Uri.parse("http://www.adriancoman.ro/stii-sa-scrii-despre/");
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);
            }
        });
    }

    private void setUpUi() {

        LinearLayout at_ll_main = (LinearLayout) findViewById(R.id.at_ll_main);

        LinearLayout.LayoutParams lp_title = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        lp_title.setMargins(20, 5, 20, 5);
        LinearLayout.LayoutParams lp_content = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        lp_content.setMargins(30, 5, 30, 10);

        String[] license_title = getResources().getStringArray(R.array.licenses_title);
        String[] license_content = getResources().getStringArray(R.array.license_content);

        Toast.makeText(context, license_title.length + "", Toast.LENGTH_LONG).show();

        for (int i = 0; i < license_title.length; i++) {
            TextView tv_title = new TextView(this);
            TextView tv_content = new TextView(this);

            tv_title.setText(license_title[i]);
            tv_title.setTextSize(16);
            tv_title.setTypeface(null, Typeface.BOLD);
            at_ll_main.addView(tv_title, lp_title);
            tv_content.setText(license_content[i]);
            tv_content.setTextSize(14);
            at_ll_main.addView(tv_content, lp_content);
        }
    }

    //region drawer

    ActionBarDrawerToggle actionBarDrawerToggle;

    private void createDrawer(Bundle savedInstanceState) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawerLayoutt = (DrawerLayout) findViewById(R.id.drawer_layout);
        ListView listView = (ListView) findViewById(R.id.left_drawer);

        drawerLayoutt.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        String[] navigationDrawerItems = getResources().getStringArray(R.array.navigation_drawer_items);
        listView.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, navigationDrawerItems));

        listView.setOnItemClickListener(new DrawerItemClickListener(context));

        TextView tv_title = new TextView(this);
        tv_title.setText("tii s scrii");
        tv_title.setTextSize(20);
        tv_title.setTextColor(getResources().getColor(R.color.white));
        toolbar.addView(tv_title);

        actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayoutt, toolbar, R.string.blank,
                R.string.blank);
        drawerLayoutt.setDrawerListener(actionBarDrawerToggle);
        setTitle("");
        // enable ActionBar app icon to behave as action to toggle nav drawer
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }

        if (savedInstanceState == null) {
            //            selectItem(0);
        }

    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        actionBarDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        actionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    //endregion

}