Android 11 is almost ready and we have got beta release from google now.
Google calling it as release candidate for final release.
Android 11 is almost ready and we have got beta release from google now.
Google calling it as release candidate for final release.
build.gradle script for a Java project looks like this:
1
| apply plugin: 'java' |
src/main/java, src/main/resource, src/test/java and src/test/resource. And it expects the source to be compatible with the current JVM it is running on. To change these properties of the ‘java’ plug-in you can use Gradle’s DSL:
1
2
| sourceSets.main.java.srcDirs = ['src/java', 'src/generated']sourceCompatibility = 1.6 |
1
2
3
4
5
6
7
8
9
10
11
12
13
| repositories { mavenLocal() maven { } mavenCentral()}repositories { ivy { }} |
1
2
3
| dependencies { compile project(':shared')} |
1
2
3
4
| dependencies { runtime group: 'org.hibernate', name: 'hibernate', version: '3.0.5' testRuntime 'org.mockito:mockito-core:1.8.4'} |
1
2
3
4
| dependencies { compile files('libs/a.jar', 'libs/b.jar') testCompile fileTree(dir: 'testlibs', include: '*.jar')} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| // Just define an empty tasktask myTaskA// Add a configuration actionmyTaskA { println "config A"}// Add an execution actionmyTaskA << { println "action A"}// Another task depending on myTaskA with configuration and actiontask myTaskB (dependsOn: myTaskA) { println "config B" doLast { println "action B" }} |
1
| $ gradle myTaskB |
1
2
3
4
5
6
7
8
| config Aconfig B:myTaskAaction A:myTaskBaction BBUILD SUCCESSFUL |
1
2
3
4
5
6
7
8
9
10
| apply plugin: 'java'… // dependencies, repositories etc.task startMain(type: JavaExec, dependsOn: classes) { main = 'mypackage.Main' args = "-x -y -z".split().toList() classpath sourceSets.main.classesDir classpath configurations.compile} |
gradle startMain prepares the classes and then starts the program using the classes and also the external dependencies as classpath.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| <modelVersion>4.0.0</modelVersion> <groupId>ch.bbv.mavendemo</groupId> <artifactId>simpleMavenDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <java.source.version>1.7</java.source.version> <junit.version>4.8.2</junit.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.1</version> <configuration> <source>${java.source.version}</source> <target>${java.source.version}</target> </configuration> </plugin> </plugins> </build></project> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| apply plugin: 'java'apply plugin: 'maven'group = 'ch.bbv.gradledemo'version = '0.0.1-SNAPSHOT'//the default artifact id is the project name, which is per default the directory name of the projectproject.ext.junitVersion='4.8.2'sourceCompatibility = 1.7targetCompatibility = 1.7repositories { mavenCentral()}dependencies { testCompile 'junit:junit:'+junitVersion} |
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Pretty hint text, and maxLines -->
<EditText android:id="@+building_list/search_box"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="type to filter"
android:inputType="text"
android:maxLines="1"/>
<!-- Set height to 0, and let the weight param expand it -->
<!-- Note the use of the default ID! This lets us use a
ListActivity still! -->
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
This will lay everything out properly, with a nice EditText above the
ListView. Next, create a ListActivity as you would normally, but add a setContentView() call in the onCreate() method so we use our recently declared layout. Remember that we ID'ed the ListView specially, with android:id="@android:id/list". This allows the ListActivity to know which ListView we want to use in our declared layout. @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filterable_listview);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
getStringArrayList());
}
Running the app now should show your previous ListView,
with a nice box above. In order to make that box do something, we need
to take the input from it, and make that input filter the list. While a
lot of people have tried to do this manually, most ListView Adapter classes come with a Filter object that can be used to perform the filtering automagically. We just need to pipe the input from the EditText into the Filter. Turns out that is pretty easy. To run a quick test, add this line to your onCreate() calladapter.getFilter().filter(s);
Notice that you will need to save your ListAdapter to a variable to make this work - I have saved my ArrayAdapter<String> from earlier into a variable called 'adapter'.EditText. This actually takes a bit of thought. You could add an OnKeyListener() to your EditText. However, this listener only receives some key events.
For example, if a user enters 'wyw', the predictive text will likely
recommend 'eye'. Until the user chooses either 'wyw' or 'eye', your OnKeyListener
will not receive a key event. Some may prefer this solution, but I
found it frustrating. I wanted every key event, so I had the choice of
filtering or not filtering. The solution is a TextWatcher. Simply create and add a TextWatcher to the EditText, and pass the ListAdapter Filter a filter request every time the text changes. Remember to remove the TextWatcher in OnDestroy()! Here is the final solution:private EditText filterText = null;
ArrayAdapter<String> adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filterable_listview);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
getStringArrayList());
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
}
};
@Override
protected void onDestroy() {
super.onDestroy();
filterText.removeTextChangedListener(filterTextWatcher);
}
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_resource);
Edit: Here a version where the image gets downloaded.String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
Bitmap mIcon1 =
BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
profile.setImageBitmap(mIcon1);
}
Drawable d = ImagesArrayList.get(0); Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
(the value @color/transparent is the color value #00000000 which I
put in res/values/color.xml file. You can also use
@android:color/transparent in later Android versions)<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...</activity>
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case REQ_CODE_PICK_IMAGE:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
}
}
}
HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
If you want to set the Parameters of any
existing HTTPClient (e.g. DefaultHttpClient or AndroidHttpClient) you
can use the function setParams().httpClient.setParams(httpParameters);
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}