Example usage for android.app Activity Activity

List of usage examples for android.app Activity Activity

Introduction

In this page you can find the example usage for android.app Activity Activity.

Prototype

Activity

Source Link

Usage

From source file:Main.java

/**
 * Read file from given file path and return data in string
 * @param filePath//from  w  w w. j  a  v  a2s.c o m
 * @return
 */
public static String readFileToString(String filePath) {
    String result = "";
    try {
        FileInputStream fileInputStream = new Activity().openFileInput(filePath);
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
        BufferedReader reader = new BufferedReader(inputStreamReader);

        String data = reader.readLine();
        while (data != null) {
            result += data;
            data = reader.readLine();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        result = "";
    }

    return result;
}

From source file:Main.java

/**
 * Clear old data and inserts new data into file.
 * @param filename//w  ww . j  a  v a  2  s.c  o  m
 * @param data
 * @return <c>true</c>, if data to file was inserted, <c>false</c> otherwise.</returns>
 */
public static boolean InsertDataToFile(String filename, String data) {
    // get file paht
    String filePath = generateFilePath(filename);
    try {
        // open file to write
        FileOutputStream fos = new Activity().openFileOutput(filePath, Context.MODE_PRIVATE);
        // write data to file
        fos.write(data.getBytes());
        // close file
        fos.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return true;
}

From source file:Main.java

/** Instantiates the mLocationManager variable if needed. */
private static final void loadLocationManager() {
    if (mLocationManager == null) {
        mLocationManager = (LocationManager) (new Activity().getApplicationContext())
                .getSystemService(Context.LOCATION_SERVICE);
    }//w  w  w .java 2  s .c o m
}

From source file:Main.java

/** Instantiates the mLocationManager variable if needed. */
private static final void loadLocationManager() {
    // TODO: Don't get Application context this way. Either pass in a static way of getting app context like in second line, or create a constructor to accept the context.
    if (mLocationManager == null) {
        mLocationManager = (LocationManager) (new Activity().getApplicationContext())
                .getSystemService(Context.LOCATION_SERVICE);
    }//  w  w  w .j a  va2s  . c  o m
    //      if (mLocationManager == null) { mLocationManager = (LocationManager) MyApp.getContext().getSystemService(Context.LOCATION_SERVICE); }
}

From source file:com.winsuk.pebbletype.WatchCommunication.java

private void sendThreadList(Context context) {
    Cursor msgCursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null,
            null);// www .  j  a  v  a2 s  .c  om
    Activity act = new Activity();
    act.startManagingCursor(msgCursor);
    ArrayList<SMSThread> threads = new ArrayList<SMSThread>();

    if (msgCursor.moveToFirst()) {
        for (int i = 0; i < msgCursor.getCount(); i++) {
            int thread_id = msgCursor.getInt(msgCursor.getColumnIndexOrThrow("thread_id"));
            SMSThread th = null;
            for (int t = 0; t < threads.size(); t++) {
                SMSThread existingTh = threads.get(t);
                if (existingTh.thread_id == thread_id) {
                    th = existingTh;
                }
            }

            if (th == null) {
                String address = msgCursor.getString(msgCursor.getColumnIndexOrThrow("address")).toString();
                String name = "";

                Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, address);
                Cursor contactCursor = context.getContentResolver().query(uri,
                        new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
                if (contactCursor.moveToFirst()) {
                    name = contactCursor.getString(contactCursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
                    contactCursor.close();
                }

                th = new SMSThread();
                th.thread_id = thread_id;
                th.address = address;
                th.name = name;
                //th.messages = new ArrayList<String>();
                threads.add(th);
            }

            /* TODO: this line is causing crashes on select few devices
            String body = msgCursor.getString(msgCursor.getColumnIndexOrThrow("body")).toString();
            if (th.messages.size() < 5) {
               th.messages.add(body);
            }
            */

            msgCursor.moveToNext();
        }
    }
    msgCursor.close();

    int limit = (threads.size() <= THREAD_LIMIT ? threads.size() : THREAD_LIMIT);
    String output = "";

    if (limit > 0) {
        // Calculate how many characters names can take up
        int availibleCharacters = 120;
        for (int i = 0; i < limit; i++) {
            availibleCharacters -= threads.get(i).address.length();
            availibleCharacters -= 2; //for ; and \n
        }
        int maxNameLength = availibleCharacters / limit - 3;

        for (int i = 0; i < limit; i++) {
            SMSThread thread = threads.get(i);

            String name = "";
            if (thread.name.length() < maxNameLength) {
                name = thread.name;
            } else {
                name = thread.name.substring(0, maxNameLength - 1);
                name += "";
            }

            output = output + thread.address + ";" + name + "\n";

            /* List messages
            for (int ii = 0; ii < thread.messages.size(); ii++) {
               output = output + thread.messages.get(ii) + "\n";
            }*/
        }
    }
    PebbleDictionary data = new PebbleDictionary();
    data.addString(KEY_THREAD_LIST, output);
    PebbleKit.sendDataToPebble(context, PEBBLE_APP_UUID, data);
}

From source file:io.github.sdsstudios.ScoreKeeper.Home.java

@Override
public io.github.sdsstudios.ScoreKeeper.Activity.Activity getActivity() {
    return io.github.sdsstudios.ScoreKeeper.Activity.Activity.HOME;
}

From source file:io.github.sdsstudios.ScoreKeeper.Home.java

private synchronized void displayRecyclerView() {

    gameDBAdapter.open();/*from  w  w  w  .ja v a2s . c o  m*/

    try {

        if (mNumRows != 0) {

            RecyclerView.LayoutManager mLayoutManager;
            mLayoutManager = new LinearLayoutManager(this);
            mRecyclerView.setLayoutManager(mLayoutManager);

            HistoryAdapter historyAdapter = new HistoryAdapter(
                    HistoryModel.getHistoryModelList(gameDBAdapter, this,
                            io.github.sdsstudios.ScoreKeeper.Activity.Activity.HOME, HistoryAdapter.UNFINISHED),
                    this, this, io.github.sdsstudios.ScoreKeeper.Activity.Activity.HOME);

            mRecyclerView.setAdapter(historyAdapter);

        } else {
            mRecyclerView.setVisibility(View.INVISIBLE);
        }
        gameDBAdapter.close();

    } catch (Exception e) {

        e.printStackTrace();
        Log.e(TAG, e.toString());

    }
}