My app uses multiple push notifications. I wish to add some kind of Intent data or any boxed-up data so that when I receive a push notification in my ParsePushBroadcastReceiver, I am able to detect what type of push notification it is and then show the user the appropriate screen. For example, if the notification is telling the user that a friend is trying to add you, it takes the user to the ContractRequest page.

This is what my Receiver currently looks like:

public class ParsePushReceiver extends ParsePushBroadcastReceiver {
    @Override
    public void onPushOpen(final Context context, final Intent intent) {
        Log.i("Push", "Notification Clicked");
        Intent activityIntent = new Intent(context, GameDetailsActivity.class);
        activityIntent.putExtras(intent.getExtras());
        activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(activityIntent);
    }
}

And this is how I typically send a push notification:

ParseQuery query = ParseInstallation.getQuery();
query.whereEqualTo(ParseUserHelper.USERNAME_VAR, contact.getUsername());
ParsePush.sendMessageInBackground(String.format("...");
....

Any ideas how I can wrap data within the notification so that when I intercept it in my receiver, I'll be able to do a switch statement which shall check what type of notification it is and then show the user the correct activity.

I am working on a android project where i need to verify some data from URL in WebView. Is there any way to pull URL from WebView?

I have tried using driver.getcurrentURL(); but it says "Object has no method "getURL".

This may turn out as a lame question, but I am a beginner and don't seem to understand the behavior of my app.

I have a SQLite data base, and a list view in the main activity. In the list view I display the List no.(row id) and other details. and on pressing the list item, a new activity opens up which displays the details in a textview and has 2 image buttons for delete and sync.

The app works just fine until I delete any entry.

Once I delete any entry the row id on the listview doesn't seem to update the row number. (if i delete the first row, the row on top shows 2(should be 1, as it is the new first row)).

However when I display the details of record it comes out correct. (the second item on the list show the row number 2)

Also when I press press an item in the list view whose position is same as the position i have deleted earlier the app crashes(Suppose i delete the first entry, after that whenever I click on the first Item on the list view to display it the app crashes)

Error I get on app crash :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aakashmaroti.fillup/com.example.aakashmaroti.fillup.DisplayDetails}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

My main activity

package com.example.aakashmaroti.fillup;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


public class StartScreen extends ActionBarActivity implements View.OnClickListener {


FavoriteList favList = new FavoriteList();

TextView rid,ts,sd;
ListView lv;
Context context=this;
Find db=new Find(this);
List<FavoriteList> favoriteList;
LinearLayout layout;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start_screen);
    Button b = (Button) findViewById(R.id.AddButton);
    b.setOnClickListener(this);
    lv = (ListView) findViewById(R.id.listview);
    try
    {
        populateListViewFromDatabase();
    } catch (Exception e)
    {
        Toast.makeText(getApplicationContext(), "Oops there has been an error "+e.toString()+"", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
            showsDialog(position);
        }
    });


}


@Override
public void onResume()
{
    super.onResume();       
    try
    {
        populateListViewFromDatabase();
    } catch (Exception e)
    {
        Toast.makeText(getApplicationContext(), "Oops there has been an error "+e.toString()+"", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_start_screen, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {

    switch (v.getId())
    {
        case R.id.AddButton:
            startActivity(new Intent(this,Form.class));
            break;

        default: break;
    }
}

public void populateListViewFromDatabase()throws Exception
{
    Find info=new Find(this);
    try
    {
        info.open();
        SimpleCursorAdapter myCursorAdapter;
        myCursorAdapter = info.listUp();
        lv.setAdapter(myCursorAdapter);
        info.close();

    } catch (SQLException e)
    {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "Oops there has been an error "+e.toString()+"", Toast.LENGTH_LONG).show();
    }
}
public void showsDialog(int pos)
{

    pos++;
    String s = "";
    s += pos;
    Intent i = new Intent(getApplicationContext(), DisplayDetails.class);
    i.putExtra("position", s);
    startActivity(i);

    try
    {
        populateListViewFromDatabase();
    } catch (Exception e)
    {
        e.printStackTrace();
    }
}      

}

The sqlite data base managing class

package com.example.aakashmaroti.fillup;

import android.app.Dialog;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Aakash Maroti on 28-Dec-14.
 */
public class Find
{
    public static final String KEY_ROWID = "_id";
    public static final String KEY_TIMESTAMP= "time_stamp";
    public static final String KEY_IS_SYNCED = "sync";
    public static final String KEY_NameOfCompany="name_of_company";



    private static final String DATABASE_NAME = "FillUpFormsDB";
    private static final String DATABASE_TABLE = "FillUpFormsTable";
    private static final int DATABASE_VERSION = 1;

    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;




    private static class DbHelper extends SQLiteOpenHelper
    {

        public DbHelper(Context context)
        {
            super(context,DATABASE_NAME,null,DATABASE_VERSION);
        }



        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                    KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                            KEY_IS_SYNCED +" TEXT NOT NULL, " +
                            KEY_TIMESTAMP +" TEXT NOT NULL, " +
                            KEY_NameOfCompany+" TEXT NOT NULL);"
            );
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
            onCreate(db);
        }     

    }  


    public Find(Context c)
    {
        ourContext = c;
    }

    public Find open()throws SQLException
    {
        ourHelper = new DbHelper(ourContext);
        ourDatabase=ourHelper.getWritableDatabase();
        return this;
    }

    public void close()
    {
        ourHelper.close();
    }


    public long createEntry(String isSynced, String timeStamp, String nameOfCompany)
    {
        ContentValues cv=new ContentValues();
        cv.put(KEY_IS_SYNCED,isSynced);
        cv.put(KEY_TIMESTAMP,timeStamp);
        cv.put(KEY_NameOfCompany,nameOfCompany);        

        return ourDatabase.insert(DATABASE_TABLE,null,cv);

    }

    public SimpleCursorAdapter listUp()
    {

        String columns[]=new String[]{KEY_ROWID,KEY_TIMESTAMP,KEY_IS_SYNCED};
        Cursor c= ourDatabase.query(DATABASE_TABLE,columns,null,null,null,null,null);
        int toViewIDs[] = new int[]{R.id.rowno,R.id.timestamp,R.id.syncdetails};
        SimpleCursorAdapter CursorAdapter;
        CursorAdapter = new SimpleCursorAdapter(ourContext,R.layout.design_row,c,columns,toViewIDs,0);
        return CursorAdapter;
    }

    public String getDetails(long row)
    {
        String columns[]=new String[] {KEY_ROWID, KEY_IS_SYNCED, KEY_TIMESTAMP,KEY_NameOfCompany};
        String result="";        
        Cursor c= ourDatabase.query(DATABASE_TABLE,columns,KEY_ROWID+"="+row,null,null,null,null);
        if(c!=null)
        {
            String r;
            c.moveToFirst();
            r="\nRecord No. : "+c.getString(0)+"\n\nSync Status:"+c.getString(1)+"\n\nTime of Creation:\n"+c.getString(2)+"\n\nName of Company:\n"+c.getString(3);
            return r;
        }

        return result;
    }

    public void DeleteRow(int pos)
    {
        ourDatabase.delete(DATABASE_TABLE,KEY_ROWID+"="+pos,null);
    }
}

the class for the new activity that shows the result.

package com.example.aakashmaroti.fillup;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import java.sql.SQLException;


public class DisplayDetails extends ActionBarActivity implements View.OnClickListener

{

    ImageButton ibSync;
    ImageButton ibDelete;
    TextView DispDetails;
    int pos;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Bundle extras = getIntent().getExtras();

        String value="1";
        if (extras != null) {
           value = extras.getString("position");
        }
        pos=Integer.parseInt(value);
        setContentView(R.layout.activity_display_details);
        ibSync=(ImageButton)findViewById(R.id.imageButtonSync);
        ibDelete=(ImageButton)findViewById(R.id.imageButtonDelete);
        DispDetails = (TextView)findViewById(R.id.textViewDisplayDetails);
        String s="";

        ibSync.setOnClickListener(this);
        ibDelete.setOnClickListener(this);

        Find info1=new Find(this);
        try
        {
            info1.open();
            s=info1.getDetails(pos);
            info1.close();

        } catch (SQLException e)
        {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), "Oops there has been an error "+e.toString()+"", Toast.LENGTH_LONG).show();
        }
        DispDetails.setText(s);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_display_details, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings)
        {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v)
    {
        if(v.getId()==R.id.imageButtonSync)
        {
            Toast.makeText(getApplicationContext(), "This functionality has not yet been added", Toast.LENGTH_LONG).show();
        }
        if(v.getId()==R.id.imageButtonDelete)
        {   Find info1=new Find(this);
            try
            {
                info1.open();
                info1.DeleteRow(pos);
                info1.close();

            } catch (SQLException e)
            {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "Oops there has been an error "+e.toString()+"", Toast.LENGTH_LONG).show();
            }


            Toast.makeText(getApplicationContext(), "This record has been successfully deleted", Toast.LENGTH_LONG).show();
            cancel();
        }
    }

    public void cancel()
    {
        this.finish();
        return;
    }
}

Xml file of a single row in the listview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text=""
        android:textStyle="bold"
        android:clickable="true"
        android:id="@+id/rowno"/>   

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text=""
        android:clickable="true"
        android:id="@+id/timestamp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:textStyle="bold"
        android:text=""
        android:clickable="true"
        android:id="@+id/syncdetails"/>

</LinearLayout>

Any help will be greatly appreciated.

Thanks in advance.

I have a problem with my layouting. In my layout I have an EditText, a DatePicker, a TimePicker and a Button. Clicking on the EditText opens the keyboard which causes the problem shown in the picture. Different methods from "android:windowSoftInputMode" did not change anything. Right now I do not have a clue how to tackle this problem.

Is it a good idea to hide the other components until a text is entered? What is the expected behaviour here?

crumbled layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="patrickengelkes.com.alleneune.activities.CreateEventActivity">


<EditText
    android:id="@+id/event_name_edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<DatePicker
    android:id="@+id/event_date_picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/event_name_edit_text"
    android:layout_centerHorizontal="true" />

<Button
    android:id="@+id/send_event_invites"
    android:text="@string/send_event_invites_to_members"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TimePicker
    android:id="@+id/event_time_picker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/send_event_invites"
    android:layout_alignLeft="@+id/event_time_picker"
    android:layout_alignStart="@+id/event_time_picker" />

Thanks in advance!

I am not a dev, but have some dev experience. I have never used Android Studio before but I wanted to look at an example app. I picked one I am very interested in, but it gives me nothing but grief just trying to import it.

https://github.com/AltBeacon/android-beacon-library-reference

Notes:

  1. I am using the latest version of Android Studio. (1.0.2). I have added in all the SDK files needed I think.
  2. I have downloaded and un-zipped Gradle 2.2.1.
  3. I am running Ubuntu 14.04.
  4. I have dealt with Eclipse for Android previously and was able to hack someone else's code to suit my needs and actually deploy an unsigned apk.
  5. The readme/install directions at the github don't really help a noob like me.

Install:

  1. I have extracted the project from the Download Zip link.
  2. For the actual import into Android Studio I choose "Open an Existing Android Studio Project" - because it looks like one.
  3. I then choose the root directory created by unzipping the zip file, in this case it is named "android-beacon-library-reference-master".
  4. But it seems to select the project's Gradle subfolder (/gradle) for the project! Which I'm quite certain is invalid. I cannot seem to get it to use the root folder.

What am I missing? Or is this not the correct way to "import" this particular app? Is this app not compatible with AS 1.0.2?.

TIA!

How do I transfer data from one device to another with Cordova/Phonegap? Most likely, I would prefer to transfer a file, though transferring a string data would work as well. I need to support Android, IOS, Windows Phone 8.x and Windows 8.x platforms.

I was thinking I could use a bluetooth plugin, but I do not see any bluetooth plugins that support all of the platforms I require.

Any suggestions?

I created an Object which is sent through Google Cloud Endpoints. Among its parameters there is one parameter of type byte[] with its getter and setter methods.

The problem is when I want to set the byte[] parameter in my app it expects somehow a parameter of type String? Does it want me to encode the byte array or what is the reason for that strange error?

When I get the parameter from the dataObject it is of type byte[] and everything is fine. I am really confused!

My Object is DataPackage defined in my Backend

 ...
 private byte[] imageThumbnail;

 public void setImageThumbnail(byte[] imageThumbnail) {
    this.imageThumbnail = imageThumbnail;
}

public byte[] getImageThumbnail() {
    return imageThumbnail;
}

Then in my app I try to set the imageByteArray

 dataPackage.setImageThumbnail(byteThumbnail); // gives error that String is expected

And this works fine

 dataPackage.getImageThumbnail() // is of type byte[]

Recently I've started to mess around with Android Studio and decided to make an app. I've made the most of my app, but I encounter a little problem. I need to memorize in a variable a number from user input, but I don't know how to that, I've tried solutions found on the internet, even here but I get an error. Can somebody help me with some ideas or the code edited which I must put in my app ? This is the java code for the activity:

public class calc_medie_teza extends ActionBarActivity implements View.OnClickListener {
EditText adaug_nota;
static final int READ_BLOCK_SIZE = 100;
TextView afisare;
TextView afisare2;
Button calc;
EditText note_nr;
EditText nota_teza;
int suma;
double medie;
double medieteza;
int nr_note = 0;
int notamedie;
int notateza;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calc_medie_teza);
    afisare = (TextView) findViewById(R.id.afisare);
    afisare2 = (TextView) findViewById(R.id.afisare2);
    calc = (Button) findViewById(R.id.calc);
    calc.setOnClickListener(this);
    note_nr = (EditText) findViewById(R.id.note_nr);
    nota_teza = (EditText) findViewById(R.id.nota_teza);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_calc_medie_teza, menu); // creare meniu
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId(); // meniu
    return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public void onClick(View v) // afisare medie
{
    calcul_medie();
}

public void buton_adauga(View v)
{
    if(note_nr == )
    suma = suma + notamedie;
    nr_note = nr_note + 1;
}
public double calcul_medie() // calculul mediei
{
    medie = suma / nr_note;
    medieteza = ((medie * 3)+ notateza)/4;
    return medieteza;
}

Here is a photo with the activity: http://onlypro.ro/img/images/ootllv2f55hnwdgi0xlv.png

Basically the app needs to add the input number to variable when I press the "Adauga nota" [Add grade] button and then I have to insert the "teza" number and when press the "Calculeaza media" [Calculate] the app will then calculate the calcul_medie() and return a decimal number. Between "Introduceti notele aici" [Add grades here] and "Adaugata nota"[Add grade] I have a Number enter text, the same is between "Introduceti teza aici" [Add thesis bere] and "Calculeaza media" [Calculate]. I don't know how to store the number the user puts in and sum it in "notamedie" variable.

I hope you understand my problem. For any questions you'll have I'll respond as soon as I can.

Thanks in advance !

I have attempted to make my own Cordova plugin (Cordova is similar to PhoneGap) to automatically upload the built Android APK after its compiled/signed/etc.

Here is the specific hook in code where the APK tries to upload: https://github.com/linagee/cordova-androidpublisher/blob/master/lib/androidPublisher_after_build.js#L109

Attempting to copy this from an example for basic APK upload: https://github.com/googlesamples/android-play-publisher-api/blob/master/v2/python/basic_upload_apks.py#L55

(Written in Python, so converting calls from python to javascript. No javascript example exist as of this post.)

It appears to upload to Google's servers, their sha1sum they send back is the same as I compute...

I attempt to put it onto the alpha track and commit the edit.

I then look in the Google Play Developer Console, and I don't see any new Alpha Track APKs for my app? I have verified that the Google Play Store listing is complete and ready to be published. (Not yet published though. Not sure if any of this is even necessary.)

Does the Google Play Developer API only work with Published APKs, or am I doing something wrong with their API?

All of the API responses do not indicate an error, so I'm hoping that Google Engineering or someone really experienced can have some feedback on my project. Thanks.

edit: Perhaps even weirder is something I just noticed. If I manually upload new APKs to the Alpha track, they are there even when I reload. When I use cordova-androidpublisher, they actually go away... Real strange now.

I user LoaderManager and CursorLoader to load the data from my database using a ContentProvider. Now, the initial load is fine. I have a ListView that display all the rows from the DB(only the names-String adapter).

Now, when I add/delete a row from the database, I want to refresh the ListView so it will display the recent changes.

Currently I just restart the loader with the method "restartLoader" whenever a change is commited but I want to ask if there is another way of doing this without restarting the loader.

Here is my activity class code: package com.silverfix.phony.activities;

import java.util.ArrayList;

import com.silverfix.phony.R;
import com.silverfix.phony.contentprovider.PhonyContentProvider;
import com.silverfix.phony.database.RingtonesTable;

import android.app.Activity;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ContentValues;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Editable;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class RingtonesActivity extends Activity implements LoaderCallbacks<Cursor>{

    private final int PICK_RINGTONE_CODE = 1;
    private final int CURSOR_LOADER_ID = 1;
    private final int EDIT_ID = 1;
    private final int DELETE_ID = 2;
    private String[] ContextCommands;
    private ArrayAdapter<String> adapter;
    private ArrayList<String> ringtones;
    private ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ringtones);
        listview = (ListView) findViewById(R.id.list);
        Button add = (Button) findViewById(R.id.add_ringtone);
        add.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, PICK_RINGTONE_CODE);
            }
        });
        fillData();
    }

    @Override
    protected void onActivityResult(int arg0, int arg1, Intent arg2) {
        super.onActivityResult(arg0, arg1, arg2);
        switch (arg0) {
        case 1: // PICK_RINGTONE_CODE
            if (arg1 == RESULT_OK) {
                Uri ringtoneURI = arg2.getData();
                String[] projection = { MediaStore.MediaColumns.DISPLAY_NAME };
                Cursor cursor = getContentResolver().query(ringtoneURI,
                        projection, null, null, null);
                cursor.moveToFirst();
                int column = cursor
                        .getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
                String displayName = cursor.getString(column);
                addRingtone(ringtoneURI, displayName);
                cursor.close();
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.ringtones, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void fillData() {
        getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);
        ringtones = new ArrayList<String>();
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, ringtones);
        ContextCommands = getResources().getStringArray(R.array.commands);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                editRingtone();
            }
        });
        registerForContextMenu(listview);
        listview.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

            @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenuInfo menuInfo) {
                if (v.getId()==R.id.list) {
                    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
                    menu.setHeaderTitle(ContextCommands[info.position]);
                    String[] menuItems = getResources().getStringArray(R.array.commands);
                    menu.add(Menu.NONE, EDIT_ID, 0, menuItems[0]);
                    menu.add(Menu.NONE, DELETE_ID, 0, menuItems[1]);
                  }
            }
        });
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch(item.getItemId()) {
        case EDIT_ID:
            editRingtone();
            return true;
        case DELETE_ID:
            String name = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
            getContentResolver().delete(PhonyContentProvider.RINGTONES_URI, RingtonesTable.COLUMN_NAME
                    + "='" + name + "'", null);
            return true;
        default:
            return super.onContextItemSelected(item);
        }
    }

    private void editRingtone() {
        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(i, PICK_RINGTONE_CODE);
    }

    private void addRingtone(Uri uri, String name) {
        String[] projection = { RingtonesTable.COLUMN_NAME };
        Cursor cursor = getContentResolver().query(
                PhonyContentProvider.RINGTONES_URI, projection,
                RingtonesTable.COLUMN_NAME + "='"+name+"'", null, null);
        if (cursor.getCount() == 0) {
            ContentValues values = new ContentValues();
            values.put(RingtonesTable.COLUMN_NAME, name);
            values.put(RingtonesTable.COLUMN_URI, uri.toString());
            getContentResolver().insert(PhonyContentProvider.RINGTONES_URI,
                    values);
            getLoaderManager().restartLoader(CURSOR_LOADER_ID, null, this);
        } else {
            Toast.makeText(this, "You already picked that ringtone!",
                    Toast.LENGTH_LONG).show();
            cursor.close();
        }
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        String[] projection = {RingtonesTable.COLUMN_ID, RingtonesTable.COLUMN_NAME, RingtonesTable.COLUMN_URI};
        return new CursorLoader(this, PhonyContentProvider.RINGTONES_URI, projection, null, null, null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        swapCursor(data);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        swapCursor(null);
    }

    private void swapCursor(Cursor cursor) {
        if(cursor != null) {
            cursor.moveToFirst();
            ringtones.clear();
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                int column = cursor.getColumnIndex(RingtonesTable.COLUMN_NAME);
                ringtones.add(cursor.getString(column));
            }
            adapter.notifyDataSetChanged();
            cursor.close();
            return;
        }
        ringtones.clear();
        adapter.notifyDataSetChanged();
    }
}

I've looked at all the SO articles I could find on this but none of the solutions work for me.

When called Camera.open(), there is a 3 second (give or take) delay where the UI thread is blocked. I have attempted to put that in a background thread. I'm currently using the solution found here (pasted below) but the 'wait' method is synchronous so it blocks the UI thread too.

What I'm looking to do is load this fragment, show a progress spinner until the camera is good to go, then show the camera on screen, but this delay is killing me and I can't seem to find any really good solution on it.

Thanks all in advance.

My fragment:

public class BarcodeFinderFragment extends Fragment implements View.OnClickListener, Camera.AutoFocusCallback, Camera.PreviewCallback {

    private static final String CAMERA_THREAD_NAME = "CAMERA_THREAD_NAME";
    private Camera mCamera;

    private CamViewFinder mPreview;
    private Handler autoFocusHandler;
    private boolean previewing = true;
    private Button noScan;
    private Button noBarcode;
    private FrameLayout preview;
    private BarcodeFinderCallback callBack;
    private ImageScanner scanner;

    private CameraHandlerThread mThread = null;


    private BarcodeFinderCallback dummyCallback = new BarcodeFinderCallback() {
        @Override
        public void onNoScanClicked() {

        }

        @Override
        public void onNoBarcodeClicked() {

        }

        @Override
        public void finishActivity() {

        }

        @Override
        public void setActivityResult(Bundle bundle) {

        }

        @Override
        public void showProgressDialog(boolean showProgress) {

        }
    };

    public static BarcodeFinderFragment newInstance() {
        return new BarcodeFinderFragment();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        try {
            callBack = (BarcodeFinderActivity) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnHeadlineSelectedListener");
        }
    }

    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_barcode_finder, container, false);

        noScan = (Button) view.findViewById(R.id.btnNoScan);
        noBarcode = (Button) view.findViewById(R.id.btnNobarcode);
        preview = (FrameLayout) view.findViewById(R.id.cameraPreview);
        noScan.setOnClickListener(this);
        noBarcode.setOnClickListener(this);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();

        autoFocusHandler = new Handler();

        //Instance barcode scanner
        scanner = new ImageScanner();
        scanner.setConfig(0, Config.X_DENSITY, 3);
        scanner.setConfig(0, Config.Y_DENSITY, 3);

        openCamera();

        mPreview = new CamViewFinder(getActivity(), mCamera, BarcodeFinderFragment.this, BarcodeFinderFragment.this);
        preview.addView(mPreview);
        callBack.showProgressDialog(false);
    }

    private void getCamera() {
        mCamera = null;
        try {
            mCamera = Camera.open();
        } catch (final Exception e) {
            Log.d("BarcodeFinderFragment", e.toString());
        }
    }

    private void openCamera() {
        if (mThread == null)
            mThread = new CameraHandlerThread(CAMERA_THREAD_NAME);

        synchronized (mThread) {
            mThread.openCamera();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        releaseCamera();
    }

    @Override
    public void onDetach() {
        super.onDetach();

        callBack = dummyCallback;
    }

    private Runnable doAutoFocus() {
        return new Runnable() {
            @Override
            public void run() {
                if (previewing) {
                    mCamera.autoFocus(BarcodeFinderFragment.this);
                }
            }
        };
    }

    private void releaseCamera() {
        if (mCamera != null) {
            previewing = false;
            mCamera.stopPreview();
            mCamera.setPreviewCallback(null);
            mCamera.release();
            mCamera = null;
        }

        callBack.finishActivity();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnNoScan:
                callBack.onNoScanClicked();
                break;

            case R.id.btnNobarcode:
                callBack.onNoBarcodeClicked();
                break;
        }
    }

    @Override
    public void onAutoFocus(boolean success, Camera camera) {
        autoFocusHandler.postDelayed(doAutoFocus(), 1000);
    }

    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {

        final Camera.Parameters parameters = camera.getParameters();
        final Camera.Size size = parameters.getPreviewSize();

        final Image barcode = new Image(size.width, size.height, "Y800");
        barcode.setData(data);

        final int result = scanner.scanImage(barcode);

        if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            final SymbolSet syms = scanner.getResults();
            for (final Symbol sym : syms) {
                final Bundle bundle = new Bundle();
                bundle.putString("result", sym.getData());
                bundle.putString("codeType", "" + sym.getType());

                callBack.setActivityResult(bundle);
            }
        }
    }

    public interface BarcodeFinderCallback {
        void onNoScanClicked();

        void onNoBarcodeClicked();

        void finishActivity();

        void setActivityResult(Bundle bundle);

        void showProgressDialog(boolean showProgress);
    }

    private class CameraHandlerThread extends HandlerThread {

        Handler mHandler = null;

        public CameraHandlerThread(String name) {
            super(name);
            callBack.showProgressDialog(true);
            start();

            mHandler = new Handler(getLooper());
        }

        synchronized void notifyCameraOpened() {
            notify();
        }

        void openCamera() {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    getCamera();
                    notifyCameraOpened();
                }
            });

            try {
                wait();
            } catch (InterruptedException e) {
                Log.d("BarcodeFinderFragment", "wait was interrupted");
            }
        }
    }
}

I've gone to the Android Developer documentation to see how I can use material design, here:

https://developer.android.com/training/material/theme.html

and here:

https://developer.android.com/training/material/get-started.html

Essentially, I would like for someone to summarize how to set up/use material design, because I feel like there is a lot of information on the developer docs, and I can't seem to wrap my mind around it. If you'd rather give me a link to a guide created by someone else, that'd be helpful as well.

I'm also using API level 19 (target SDK version 19) and from what I can see, I'll need to use com.android.support:cardview-v7:21.0.+

I'm also using Android Studio, and not eclipse.

appView is cordovaActivity.appVeiw DownloadListener is webkit.DownloadListener I am also using Crosswalk in scenario.

DownloadListener dl = new DownloadListener() {          
  public void onDownloadStart(String url, String userAgent,
  String contentDisposition, String mimetype,
  long contentLength) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
    finish();
  }
};
appView.setDownloadListener(dl);

it give err while compile

sample.java:###: error: cannot find symbol
    [javac]         appView.setDownloadListener(dl);
    [javac]                     ^`enter code here`
    [javac]   symbol:   method setDownloadListener(DownloadListener)
    [javac]   location: variable appView of type CordovaWebView
    [javac] Note: Some input files use or override a deprecated API.

Any idea how to resolve this issue?

I'm using the Class Table Inheritance architecture with my application and have read Fowler. When mapping my database tables to classes in code, I've realized I have no need for an "ID" property on my derived classes, and, in fact, it can cause issues if it has the same name because it hides the base class property.

Do my child tables need to have their own surrogate primary keys, or should the foreign keys relating them to their parent record also serve as the primary key for the child records? Fowler doesn't get that specific on CTI. I'm used to always having surrogate keys, so a departure from this convention doesn't feel quite right and if there is a good reason to stick to it, I'll take it.

From two books' review

Daniel Bovet and Marco Cesati. Understanding the Linux Kernel (2nd Edition or newer):

Note: this book has some tendency to function as a play-by-play of what happens inside Linux (on an x86) as opposed to a design book. You may find the BSD book or the Love book more design-oriented.

Robert Love. Linux Kernel Development:

We received some complaints about the 2003 edition containing too much play-by-play material, but the 2005 edition has received favorable student reviews. You may find that the BSD book provides more historical and design perspective. You should also know that people familiar with other operating systems may dispute some historical descriptions and claims of architectural novelty.

What differences are between "play-by-play", design and implementation of an OS? For example, how do they differ in terms of what they consider and what they want to accomplish?

What do "play-by-play", design and implementation of an OS mean? I don't know what "play-by-play" mean here. Does "design" mean creating a logical/abstract model, and does implementation mean implementing the logical/abastract model using hardware and programming?

I am always confused by the words "design" and "implementation" used in the tiles of books on OS, database, programming languages. There are also other books in the areas without the words. In general, what do such titles imply about the books' topics?

Are there other aspects about operating systems, besides design and implementation?

Thanks.

I have this folder having all my program files ".cpp" , ".h" and resource ".glade" files .

I'd like to separate *.h files in an Include folder and *.cpp in a source file . I compiled using Cmake for everything on the same folder, but i had a hard time building from different folders (include and source folders). How do i write the CMakeLists.txt file such it generates a build folder and put in all executables.

Let's assume within my project which is GPLv3 based I'm using a single library called a-lib.jar. That jar itself is licensed using Apache v2 license, so I should be fine with the GPL as long as I respect the Apache v2 terms (basicly inclueding the license file).

Now when I look into the a-lib.jar that I'm using I see that it is using many other dependencies (packaged within a-lib.jar):

  • b-lib.jar
  • c-lib.jar
  • d-lib.jar

All of them are licensed on open source licenses, but the licenses may differ. E.g.:

  • b-lib.jar is licensed under MIT
  • c-lib.jar is licensed under Apache v2
  • d-lib.jar is licensed under some propriatary open source license

The resulting file that I would like to release would look like this then:

myproject.jar
|--a-lib.jar
   |--b-lib.jar
   |--c-lib.jar
   |--d-lib.jar

My question is: in order to avoid legal issues, do I have to comply with all the terms of the dependencies of the library that my project depends on? E.g. do I have to place some NOTICE file somewhere, saying that I'm using b-lib.jar and that it is under MIT? Then again: you can play that game forever: b-lib.jar may also include other 3rd-party licenses and so on and on.

Do I have to check EVERY SINGLE component and comply with it's terms, even if MY software is not useing it but instead a lib that I'm using is useing it? Or am I fine if I just take care of my projects dependencies and don't have to care about 3rd party dependencies? (Basic idea behind that would be that the creator of the a-lib.jar which released it under apache v2 is responsible for it's content).

Besides of that: is the situation of the example above any different if the 3rd party dependencies are not child-jars within the a-lib.jar but instead a-lib would be delivered as a maven project with dependencies to b-lib, c-lib and d-lib and those 3rd party dependencies would be packaged directly into my project *.jar file? So the resulting file would be:

myproject.jar
|--a-lib.jar
|--b-lib.jar
|--c-lib.jar
|--d-lib.jar

Intro

We can easily find summaries about the pros of the BEAM (Erlang) Virtual Machine. Finding good summaries of the cons is much harder [1]. Because of that one can spend a significant amount of time to find such information. Such information can be very valuable for people that would like to invest in the BEAM VM and all that depends on it. So let's list some BEAM issues/cons.

Question Description

What are the performance limitations? How does it scale to multiple (to how many?) cores on one machine? How is it performing on multiple hosts? What limitations does no shared state implicate? Stability? Flexibility? [2]

Please try to stick to the topic and not talk about the programming languages that run on BEAM like e.g. Erlang, Elixir or LFE.

[1] I think this applies not only to this tech.

[2] Please try to only summarize the answers to this (example) questions. In more depth explanations are in my opinion better for separate (StackExchange) questions.

I am extremely new to programming, and am attempting to learn Python so that I can create small programs to help in my research. I am completely new to programming, apart from some basic code in Stata. I'm trying to learn Python because I've been told that it's one of the best languages for beginners like myself.

Fortunately, my brother is a very capable programmer, and helped set me up with Python and Django. Unfortunately, he's on the West Coast and I'm on the East Coast, and the time difference and respective work schedules make it difficult for him to help me. So I turn to you.

Problem

I am working my way through the Django tutorials, and I am on the third tutorial: https://docs.djangoproject.com/en/1.7/intro/tutorial03/

I'm not sure if this matters, but I am working on a Macintosh w/ Mavericks.

The root directory in which I am working is 'Test2'. The directory structure is:

/Users/me/src/collact/collact/test2/

Within 'test2', and per the previous two tutorials, I have '/polls' and '/templates' folders.

My polls/views.py file has the following text:

from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

My polls/urls.py file has the following text:

from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index'),
)

Finally, in /test2/, I have a urls python file as well (.py). It has the text:

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

As far as I can tell, this is what the tutorial prescribes. Unfortunately, when I run the server using: python manage.py runserver, the website gives me an error/404 message:

Page not found (404)
Request Method:
GET Request
URL:    http://localhost:8000/polls/ Using the URLconf defined in
test2.urls, Django tried these URL patterns, in this order: ^admin/
The current URL, polls/, didn't match any of these. You're seeing this
error because you have DEBUG = True in your Django settings file.
Change that to False, and Django will display a standard 404 page.

Does anyone have any idea how I can fix this? I know that this is a really stupid question, but I have been trying to figure it out for the past day or two, and unfortunately I'm just not familiar enough with programming to solve this on my own.

I use IE mostly and Opera Mini a little bit. What I've been wondering, do Opera Mini and UC Browser use their own rendering engine (WebKit and ???) or are they more or less skins on the Trident engine?

I'm creating a little rpg fight program just for fun and to practice my java (I'm pretty new hehe).

I have a class called Dice with a method called d20 that rolls a random number between 1 and 20. The method will be used frequently by all other classes in the program.

My question is, should I create a single instance of the Dice class in my main method that can be called by all the other classes too. Does that work? Does it need to be declared as a public reference variable to work? Is this just a poor practice?

Should I be making the method static instead so that I don't need to make an instance of the object at all?

Or should I create the object when the call is to be made and then throw it away afterwards using garbage collection?

I'm not sure the first way even works. The latter two I don't know which is good practice.

My main motivation here is to understand what the best practice is and why.