Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2012 University of Washington
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import android.content.Context;

import android.content.SharedPreferences;

public class Main {
    /**
     * This is the name of the shared preference to which collect util will save
     * the things it must retain. At the moment this is only the row id that is
     * being edited. The vast majority of state should not be saved here.
     */
    private static final String SHARED_PREFERENCE_NAME = "CollectUtil_Preference";
    /**
     * This is the table id of the tableId that will be receiving an add row. This
     * is necessary because javascript views can launch adds for tables other than
     * themselves, and this preference will store which table id the row should be
     * added to.
     */
    private static final String PREFERENCE_KEY_TABLE_ID_ADD = "tableIdAdd";

    /**
     * Retrieves the tableId that was stored during the call to
     * {@link CollectUtil#launchCollectToAddRow(Activity, Intent, String)} .
     * Removes the tableId so that future calls to the same method will return
     * null.
     *
     * @param context
     * @return the stored tableId, or null if no tableId was found.
     */
    public static String retrieveAndRemoveTableIdForAddRow(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE);
        String tableId = sharedPreferences.getString(PREFERENCE_KEY_TABLE_ID_ADD, null);
        sharedPreferences.edit().remove(PREFERENCE_KEY_TABLE_ID_ADD).commit();
        return tableId;
    }
}