Category Archives: Uncategorized

Homepage Only Links

this code displays a link only on the homepage:

<?
$currentpage = $_SERVER[‘REQUEST_URI’];

if ($currentpage == “” || $currentpage == “/” || $currentpage == “/index.php” || $currentpage == “/index.php/”) {
echo “Site sponsored by <a href=’http://www.quickplaysport.com/’ title=’Football Equipment from quickplaysport’>Quickplay Sport</a>”;
}

?>

 

how to add a new page layout file in Magento

To add a new layout first you need to edit app/code/core/Mage/Page/etc/config.xml

add a new block like this:

<three_columns_cycle module=”page” translate=”label”>
<label>3 columns Cycle BG</label>
<template>page/3columns_cycle.phtml</template>
<layout_handle>page_three_columns_cycle</layout_handle>
</three_columns_cycle>

Now create the .phtml template file and put it in:

app/design/frontend/base/default/template/page

download image and swap image

http://blog.vogella.com/2011/06/14/android-downloadmanager-example/

 

code:

package com.quickplaysport.download2;

import android.app.Activity;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {
private long enqueue;
private DownloadManager dm;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

 

// this broadcast reveiver means it has to be on button click
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, 0);
Query query = new Query();
query.setFilterById(enqueue);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS);

// if the download successfull then swap the image
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)) {

ImageView view = (ImageView) findViewById(R.id.imageView1);
String uriString = c
.getString(c
.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
view.setImageURI(Uri.parse(uriString));

Uri myDownloadedFile = dm.getUriForDownloadedFile(downloadId);
}
}
}
}
};

registerReceiver(receiver, new IntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

public void onClick(View view) {
dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(
Uri.parse(“http://www.wetterzentrale.de/pics/MS_644_ens.png”));
enqueue = dm.enqueue(request);

}

public void showDownload(View view) {
Intent i = new Intent();
i.setAction(DownloadManager.ACTION_VIEW_DOWNLOADS);
startActivity(i);
}

// try getting the uri of the downloaded file and setting it to a textview
}

reading data from internal storage

public void read(View view){
String myFilename = “freekick”;
String readData = “”;

openFile(myFilename);

}

publicĀ  void openFile(String myFilename) {
String value = “”;
FileInputStream fis;

try {
fis = openFileInput(myFilename);
byte[] input = new byte[fis.available()];
while(fis.read(input) != -1){
value += new String(input);
}
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
TextView myTextView = (TextView) findViewById(R.id.textView);
myTextView.setText(value);
}
}