Skip to content

Instantly share code, notes, and snippets.

View pwittchen's full-sized avatar
🎯
Focusing

Piotr Wittchen pwittchen

🎯
Focusing
View GitHub Profile
@pwittchen
pwittchen / FromHtmlImageActivity.java
Last active February 6, 2016 03:14
Exemplary class which shows, how to display image gathered from the internet inside the TextView in Android application having only html code.
public class FromHtmlImageActivity extends Activity {
private TextView sampleTextView;
private Spanned spannedValue;
private String stringWithHtml;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
@pwittchen
pwittchen / MyFragment.java
Last active December 21, 2015 03:58
Examplary code showing how to change Fragment layout on orientation change in Android.
public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
View view = inflater.inflate(R.layout.my_fragment, container, false);
// Find your buttons in view, set up onclicks, set up callbacks to your parent fragment or activity here.
// You can create ViewHolder or separate method for that.
// example of accessing views: TextView textViewExample = (TextView) view.findViewById(R.id.text_view_example);
// textViewExample.setText("example");
package com.github.volley.example.toolbox;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
public class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache {
public BitmapLruCache(int maxSize) {
super(maxSize);
package com.github.volley.example.toolbox;
import android.content.Context;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.github.volley.example.toolbox.BitmapLruCache;
/**
imageView = (ImageView) findViewById(R.id.iv_image);
// ...
String imageUrl = "http://www.example.com/image.jpg";
VolleyHelper.init(this); // we can call this method in other place - e.g. in class extending Application class
// and refer to application context insted of activity context
ImageLoader imageLoader = VolleyHelper.getImageLoader();
body {
font-size: 1.0em;
color: rgb(0,0,0);
text-align: justify;
/* background: rgba(217, 217, 217, 1.0); you can set your background here,
it's kind of fix for older versions of Android OS */
}
@media screen and (-webkit-device-pixel-ratio: 1.5) {
/* CSS for high-density screens */
package com.github.sample.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
<declare-styleable name="JustifiedTextView">
<attr name="text" format="reference" />
</declare-styleable>
<com.github.sample.view.JustifiedTextView
android:id="@+id/tv_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
// ...
private JustifiedTextView tvInformation;
public void onCreate() {
tvInformation = (JustifiedTextView) findViewById(R.id.tv_information);
tVinformation.setText("sample text");
}
// ...